8 cfg = config.services.harmonia;
9 format = pkgs.formats.toml { };
11 signKeyPaths = cfg.signKeyPaths ++ lib.optional (cfg.signKeyPath != null) cfg.signKeyPath;
12 credentials = lib.imap0 (i: signKeyPath: {
13 id = "sign-key-${builtins.toString i}";
20 enable = lib.mkEnableOption "Harmonia: Nix binary cache written in Rust";
22 signKeyPath = lib.mkOption {
23 type = lib.types.nullOr lib.types.path;
25 description = "DEPRECATED: Use `services.harmonia.signKeyPaths` instead. Path to the signing key to use for signing the cache";
28 signKeyPaths = lib.mkOption {
29 type = lib.types.listOf lib.types.path;
31 description = "Paths to the signing keys to use for signing the cache";
34 package = lib.mkPackageOption pkgs "harmonia" { };
36 settings = lib.mkOption {
37 inherit (format) type;
40 Settings to merge with the default configuration.
41 For the list of the default configuration, see <https://github.com/nix-community/harmonia/tree/master#configuration>.
47 config = lib.mkIf cfg.enable {
48 warnings = lib.optional (
49 cfg.signKeyPath != null
50 ) "`services.harmonia.signKeyPath` is deprecated, use `services.harmonia.signKeyPaths` instead";
51 nix.settings.extra-allowed-users = [ "harmonia" ];
52 users.users.harmonia = {
56 users.groups.harmonia = { };
58 systemd.services.harmonia = {
59 description = "harmonia binary cache service";
61 requires = [ "nix-daemon.socket" ];
62 after = [ "network.target" ];
63 wantedBy = [ "multi-user.target" ];
66 CONFIG_FILE = format.generate "harmonia.toml" cfg.settings;
67 SIGN_KEY_PATHS = lib.strings.concatMapStringsSep " " (
68 credential: "%d/${credential.id}"
70 # Note: it's important to set this for nix-store, because it wants to use
71 # $HOME in order to use a temporary cache dir. bizarre failures will occur
73 HOME = "/run/harmonia";
77 ExecStart = lib.getExe cfg.package;
80 Restart = "on-failure";
84 RuntimeDirectory = "harmonia";
85 LoadCredential = builtins.map (credential: "${credential.id}:${credential.path}") credentials;
91 CapabilityBoundingSet = "";
92 ProtectKernelModules = true;
93 ProtectKernelTunables = true;
94 ProtectControlGroups = true;
95 ProtectKernelLogs = true;
96 ProtectHostname = true;
98 RestrictRealtime = true;
99 MemoryDenyWriteExecute = true;
101 ProtectProc = "invisible";
102 RestrictNamespaces = true;
103 SystemCallArchitectures = "native";
104 PrivateNetwork = false;
106 PrivateDevices = true;
107 PrivateMounts = true;
108 NoNewPrivileges = true;
109 ProtectSystem = "strict";
111 LockPersonality = true;
112 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6";