2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nix-serve;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.nix-serve = {
|
|
|
|
enable = mkEnableOption "nix-serve, the standalone Nix binary cache server";
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-07-14 22:03:04 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 5000;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Port number where nix-serve will listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bindAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
IP address where nix-serve will bind its listening socket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-19 23:45:15 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Open ports in the firewall for nix-serve.";
|
2022-01-19 23:45:15 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
secretKeyFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The path to the file used for signing derivation data.
|
|
|
|
Generate with:
|
|
|
|
|
|
|
|
```
|
|
|
|
nix-store --generate-binary-cache-key key-name secret-key-file public-key-file
|
|
|
|
```
|
|
|
|
|
|
|
|
For more details see <citerefentry><refentrytitle>nix-store</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraParams = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra command line parameters for nix-serve.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.nix-serve = {
|
|
|
|
description = "nix-serve binary cache server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
path = [ config.nix.package.out pkgs.bzip2.bin ];
|
|
|
|
environment.NIX_REMOTE = "daemon";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
script = ''
|
|
|
|
${lib.optionalString (cfg.secretKeyFile != null) ''
|
|
|
|
export NIX_SECRET_KEY_FILE="$CREDENTIALS_DIRECTORY/NIX_SECRET_KEY_FILE"
|
|
|
|
''}
|
|
|
|
exec ${pkgs.nix-serve}/bin/nix-serve --listen ${cfg.bindAddress}:${toString cfg.port} ${cfg.extraParams}
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5s";
|
|
|
|
User = "nix-serve";
|
2021-07-18 21:22:44 +00:00
|
|
|
Group = "nix-serve";
|
|
|
|
DynamicUser = true;
|
2021-12-06 16:07:01 +00:00
|
|
|
LoadCredential = lib.optionalString (cfg.secretKeyFile != null)
|
|
|
|
"NIX_SECRET_KEY_FILE:${cfg.secretKeyFile}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2022-01-19 23:45:15 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|