11 cfg = config.services.nix-serve;
15 services.nix-serve = {
16 enable = mkEnableOption "nix-serve, the standalone Nix binary cache server";
22 Port number where nix-serve will listen on.
26 bindAddress = mkOption {
30 IP address where nix-serve will bind its listening socket.
34 package = mkPackageOption pkgs "nix-serve" { };
36 openFirewall = mkOption {
39 description = "Open ports in the firewall for nix-serve.";
42 secretKeyFile = mkOption {
43 type = types.nullOr types.str;
46 The path to the file used for signing derivation data.
50 nix-store --generate-binary-cache-key key-name secret-key-file public-key-file
53 For more details see {manpage}`nix-store(1)`.
57 extraParams = mkOption {
58 type = types.separatedString " ";
61 Extra command line parameters for nix-serve.
67 config = mkIf cfg.enable {
68 nix.settings = lib.optionalAttrs (lib.versionAtLeast config.nix.package.version "2.4") {
69 extra-allowed-users = [ "nix-serve" ];
72 systemd.services.nix-serve = {
73 description = "nix-serve binary cache server";
74 after = [ "network.target" ];
75 wantedBy = [ "multi-user.target" ];
78 config.nix.package.out
81 environment.NIX_REMOTE = "daemon";
84 ${lib.optionalString (cfg.secretKeyFile != null) ''
85 export NIX_SECRET_KEY_FILE="$CREDENTIALS_DIRECTORY/NIX_SECRET_KEY_FILE"
87 exec ${cfg.package}/bin/nix-serve --listen ${cfg.bindAddress}:${toString cfg.port} ${cfg.extraParams}
96 LoadCredential = lib.optionalString (
97 cfg.secretKeyFile != null
98 ) "NIX_SECRET_KEY_FILE:${cfg.secretKeyFile}";
102 networking.firewall = mkIf cfg.openFirewall {
103 allowedTCPPorts = [ cfg.port ];