2015-05-13 17:54:25 +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-06-18 15:28:35 +00:00
|
|
|
type = types.port;
|
2015-05-13 17:54:25 +00:00
|
|
|
default = 5000;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-05-13 17:54:25 +00:00
|
|
|
Port number where nix-serve will listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bindAddress = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2015-05-13 17:54:25 +00:00
|
|
|
default = "0.0.0.0";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-05-13 17:54:25 +00:00
|
|
|
IP address where nix-serve will bind its listening socket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-17 23:14:02 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Open ports in the firewall for nix-serve.";
|
2022-01-17 23:14:02 +00:00
|
|
|
};
|
|
|
|
|
2015-06-18 02:10:23 +00:00
|
|
|
secretKeyFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The path to the file used for signing derivation data.
|
2019-02-18 18:33:36 +00:00
|
|
|
Generate with:
|
|
|
|
|
2022-08-13 09:56:56 +00:00
|
|
|
<programlisting>
|
2019-02-18 18:33:36 +00:00
|
|
|
nix-store --generate-binary-cache-key key-name secret-key-file public-key-file
|
2022-08-13 09:56:56 +00:00
|
|
|
</programlisting>
|
2019-02-18 18:33:36 +00:00
|
|
|
|
|
|
|
For more details see <citerefentry><refentrytitle>nix-store</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
|
2015-06-18 02:10:23 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-05-13 17:54:25 +00:00
|
|
|
extraParams = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.separatedString " ";
|
2015-05-13 17:54:25 +00:00
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-05-13 17:54:25 +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" ];
|
|
|
|
|
2016-04-24 11:06:04 +00:00
|
|
|
path = [ config.nix.package.out pkgs.bzip2.bin ];
|
2015-05-13 17:54:25 +00:00
|
|
|
environment.NIX_REMOTE = "daemon";
|
2021-12-01 21:19:58 +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}
|
|
|
|
'';
|
2015-05-13 17:54:25 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
2018-03-05 19:32:42 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5s";
|
2015-06-18 02:10:23 +00:00
|
|
|
User = "nix-serve";
|
2020-12-12 08:29:40 +00:00
|
|
|
Group = "nix-serve";
|
|
|
|
DynamicUser = true;
|
2021-12-01 21:19:58 +00:00
|
|
|
LoadCredential = lib.optionalString (cfg.secretKeyFile != null)
|
|
|
|
"NIX_SECRET_KEY_FILE:${cfg.secretKeyFile}";
|
2015-05-13 17:54:25 +00:00
|
|
|
};
|
|
|
|
};
|
2022-01-17 23:14:02 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
2015-05-13 17:54:25 +00:00
|
|
|
};
|
|
|
|
}
|