peerix/module.nix

166 lines
4.2 KiB
Nix
Raw Permalink Normal View History

2021-10-17 06:01:40 -04:00
{ lib, config, pkgs, ... }:
let
cfg = config.services.peerix;
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 = ''
File containing the private key to sign the derivations with.
2021-10-17 06:01:40 -04:00
'';
2022-07-14 00:02:15 -04:00
};
2021-10-17 06:01:40 -04:00
publicKeyFile = lib.mkOption {
type = types.nullOr types.path;
default = null;
description = ''
File containing the public key to sign the derivations with.
'';
};
publicKey = lib.mkOption {
2021-10-31 21:28:01 -04:00
type = types.nullOr types.str;
default = null;
description = ''
The public key to sign the derivations with.
2021-10-17 06:01:40 -04:00
'';
};
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-31 21:18:12 -04:00
package = mkOption {
type = types.package;
default = (import ./default.nix).default or pkgs.peerix;
defaultText = literalExpression "pkgs.peerix";
description = "The package to use for peerix";
};
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) [
cfg.privateKeyFile
2021-10-17 09:03:26 -04:00
])
];
ExecPaths = [
"/nix/store"
];
2021-10-17 06:34:40 -04:00
Environment = lib.mkIf (cfg.privateKeyFile != null) [
"NIX_SECRET_KEY_FILE=${cfg.privateKeyFile}"
2021-10-17 06:01:40 -04:00
];
};
script = ''
2021-10-31 21:18:12 -04:00
exec ${cfg.package}/bin/peerix
2021-10-17 06:01:40 -04:00
'';
};
nix = {
2022-07-14 00:02:15 -04:00
settings = {
substituters = [
"http://127.0.0.1:12304/"
];
trusted-public-keys = [
(lib.mkIf (cfg.publicKeyFile != null) (builtins.readFile cfg.publicKeyFile))
(lib.mkIf (cfg.publicKey != null) cfg.publicKey)
];
};
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 ];
};
};
}