2021-10-17 06:01:40 -04:00
|
|
|
{ lib, config, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.peerix;
|
|
|
|
|
|
|
|
peerix = pkgs.callPackage ./default.nix {};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = with lib; {
|
|
|
|
services.peerix = {
|
|
|
|
enable = lib.mkEnableOption "peerix";
|
|
|
|
|
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Defines whether or not firewall ports should be opened for it.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
privateKeyFile = lib.mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The private key to sign the derivations with.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
publicKeyFile = lib.mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The private key to sign the derivations with.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
type = with types; oneOf [ str int ];
|
|
|
|
default = "nobody";
|
|
|
|
description = ''
|
|
|
|
The user the service will use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = lib.mkOption {
|
|
|
|
type = with types; oneOf [ str int ];
|
|
|
|
default = "nobody";
|
|
|
|
description = ''
|
|
|
|
The user the service will use.
|
|
|
|
'';
|
|
|
|
};
|
2021-10-18 08:50:16 -04:00
|
|
|
|
|
|
|
globalCacheTTL = lib.mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
How long should nix store narinfo files.
|
|
|
|
|
|
|
|
If not defined, the module will not reconfigure the entry.
|
|
|
|
If it is defined, this will define how many seconds a cache entry will
|
|
|
|
be stored.
|
|
|
|
|
|
|
|
By default not given, as it affects the UX of the nix installation.
|
|
|
|
'';
|
2021-10-18 08:55:07 -04:00
|
|
|
};
|
2021-10-17 06:01:40 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf (cfg.enable) {
|
|
|
|
systemd.services.peerix = {
|
2021-10-18 09:29:00 -04:00
|
|
|
enable = true;
|
2021-10-17 06:01:40 -04:00
|
|
|
description = "Local p2p nix caching daemon";
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
|
2021-10-17 09:03:26 -04:00
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateIPC = true;
|
|
|
|
PrivateUsers = true;
|
2021-10-17 06:01:40 -04:00
|
|
|
|
2021-10-17 09:03:26 -04:00
|
|
|
SystemCallFilters = [
|
|
|
|
"@aio"
|
|
|
|
"@basic-io"
|
|
|
|
"@file-system"
|
|
|
|
"@io-event"
|
|
|
|
"@process"
|
|
|
|
"@network-io"
|
|
|
|
"@timer"
|
|
|
|
"@signal"
|
|
|
|
"@alarm"
|
|
|
|
];
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
2021-10-17 06:01:40 -04:00
|
|
|
|
2021-10-17 09:03:26 -04:00
|
|
|
ProtectSystem = "full";
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
RestrictNamespaces = "";
|
2021-10-17 06:01:40 -04:00
|
|
|
|
2021-10-17 09:03:26 -04:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
ReadOnlyPaths = lib.mkMerge [
|
|
|
|
([
|
|
|
|
"/nix/var"
|
|
|
|
"/nix/store"
|
|
|
|
])
|
2021-10-17 06:01:40 -04:00
|
|
|
|
2021-10-17 09:03:26 -04:00
|
|
|
(lib.mkIf (cfg.privateKeyFile != null) [
|
|
|
|
(toString cfg.privateKeyFile)
|
|
|
|
])
|
|
|
|
];
|
|
|
|
ExecPaths = [
|
|
|
|
"/nix/store"
|
|
|
|
];
|
2021-10-17 06:34:40 -04:00
|
|
|
Environment = lib.mkIf (cfg.privateKeyFile != null) [
|
|
|
|
"NIX_SECRET_KEY_FILE=${toString cfg.privateKeyFile}"
|
2021-10-17 06:01:40 -04:00
|
|
|
];
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
exec ${peerix}/bin/peerix
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nix = {
|
|
|
|
binaryCaches = [
|
|
|
|
"http://127.0.0.1:12304/"
|
|
|
|
];
|
2021-10-17 06:34:40 -04:00
|
|
|
binaryCachePublicKeys = lib.mkIf (cfg.publicKeyFile != null) [
|
|
|
|
(builtins.readFile cfg.publicKeyFile)
|
2021-10-17 06:01:40 -04:00
|
|
|
];
|
2021-10-18 08:50:16 -04:00
|
|
|
|
|
|
|
extraOptions = lib.mkIf (cfg.globalCacheTTL != null) ''
|
2021-10-18 09:09:07 -04:00
|
|
|
narinfo-cache-negative-ttl = ${toString cfg.globalCacheTTL}
|
|
|
|
narinfo-cache-positive-ttl = ${toString cfg.globalCacheTTL}
|
2021-10-18 08:50:16 -04:00
|
|
|
'';
|
2021-10-17 06:01:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = lib.mkIf (cfg.openFirewall) {
|
|
|
|
allowedTCPPorts = [ 12304 ];
|
|
|
|
allowedUDPPorts = [ 12304 ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|