1 { config, pkgs, lib, ... }:
3 cfg = config.services.harmonia;
4 format = pkgs.formats.toml { };
6 signKeyPaths = cfg.signKeyPaths ++ lib.optional (cfg.signKeyPath != null) cfg.signKeyPath;
7 credentials = lib.imap0 (i: signKeyPath: {
8 id = "sign-key-${builtins.toString i}";
15 enable = lib.mkEnableOption "Harmonia: Nix binary cache written in Rust";
17 signKeyPath = lib.mkOption {
18 type = lib.types.nullOr lib.types.path;
20 description = "DEPRECATED: Use `services.harmonia.signKeyPaths` instead. Path to the signing key to use for signing the cache";
23 signKeyPaths = lib.mkOption {
24 type = lib.types.listOf lib.types.path;
26 description = "Paths to the signing keys to use for signing the cache";
29 package = lib.mkPackageOption pkgs "harmonia" { };
31 settings = lib.mkOption {
32 inherit (format) type;
35 Settings to merge with the default configuration.
36 For the list of the default configuration, see <https://github.com/nix-community/harmonia/tree/master#configuration>.
42 config = lib.mkIf cfg.enable {
43 warnings = lib.optional (cfg.signKeyPath != null)
44 "`services.harmonia.signKeyPath` is deprecated, use `services.harmonia.signKeyPaths` instead";
45 nix.settings.extra-allowed-users = [ "harmonia" ];
46 users.users.harmonia = {
50 users.groups.harmonia = { };
52 systemd.services.harmonia = {
53 description = "harmonia binary cache service";
55 requires = [ "nix-daemon.socket" ];
56 after = [ "network.target" ];
57 wantedBy = [ "multi-user.target" ];
60 CONFIG_FILE = format.generate "harmonia.toml" cfg.settings;
61 SIGN_KEY_PATHS = lib.strings.concatMapStringsSep " " (
62 credential: "%d/${credential.id}"
64 # Note: it's important to set this for nix-store, because it wants to use
65 # $HOME in order to use a temporary cache dir. bizarre failures will occur
67 HOME = "/run/harmonia";
71 ExecStart = lib.getExe cfg.package;
74 Restart = "on-failure";
78 RuntimeDirectory = "harmonia";
79 LoadCredential = builtins.map (credential: "${credential.id}:${credential.path}") credentials;
85 CapabilityBoundingSet = "";
86 ProtectKernelModules = true;
87 ProtectKernelTunables = true;
88 ProtectControlGroups = true;
89 ProtectKernelLogs = true;
90 ProtectHostname = true;
92 RestrictRealtime = true;
93 MemoryDenyWriteExecute = true;
95 ProtectProc = "invisible";
96 RestrictNamespaces = true;
97 SystemCallArchitectures = "native";
98 PrivateNetwork = false;
100 PrivateDevices = true;
101 PrivateMounts = true;
102 NoNewPrivileges = true;
103 ProtectSystem = "strict";
105 LockPersonality = true;
106 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6";