1 { config, pkgs, lib, ... }:
6 cfg = config.services.nix-serve;
10 services.nix-serve = {
11 enable = mkEnableOption "nix-serve, the standalone Nix binary cache server";
17 Port number where nix-serve will listen on.
21 bindAddress = mkOption {
25 IP address where nix-serve will bind its listening socket.
29 package = mkPackageOption pkgs "nix-serve" { };
31 openFirewall = mkOption {
34 description = "Open ports in the firewall for nix-serve.";
37 secretKeyFile = mkOption {
38 type = types.nullOr types.str;
41 The path to the file used for signing derivation data.
45 nix-store --generate-binary-cache-key key-name secret-key-file public-key-file
48 For more details see {manpage}`nix-store(1)`.
52 extraParams = mkOption {
53 type = types.separatedString " ";
56 Extra command line parameters for nix-serve.
62 config = mkIf cfg.enable {
63 nix.settings = lib.optionalAttrs (lib.versionAtLeast config.nix.package.version "2.4") {
64 extra-allowed-users = [ "nix-serve" ];
67 systemd.services.nix-serve = {
68 description = "nix-serve binary cache server";
69 after = [ "network.target" ];
70 wantedBy = [ "multi-user.target" ];
72 path = [ config.nix.package.out pkgs.bzip2.bin ];
73 environment.NIX_REMOTE = "daemon";
76 ${lib.optionalString (cfg.secretKeyFile != null) ''
77 export NIX_SECRET_KEY_FILE="$CREDENTIALS_DIRECTORY/NIX_SECRET_KEY_FILE"
79 exec ${cfg.package}/bin/nix-serve --listen ${cfg.bindAddress}:${toString cfg.port} ${cfg.extraParams}
88 LoadCredential = lib.optionalString (cfg.secretKeyFile != null)
89 "NIX_SECRET_KEY_FILE:${cfg.secretKeyFile}";
93 networking.firewall = mkIf cfg.openFirewall {
94 allowedTCPPorts = [ cfg.port ];