1 { config, pkgs, lib, ... }:
6 cfg = config.services.cachix-watch-store;
9 meta.maintainers = [ lib.maintainers.jfroche lib.maintainers.domenkozar ];
11 options.services.cachix-watch-store = {
12 enable = mkEnableOption "Cachix Watch Store: https://docs.cachix.org";
14 cacheName = mkOption {
16 description = "Cachix binary cache name";
19 cachixTokenFile = mkOption {
22 Required file that needs to contain the cachix auth token.
26 signingKeyFile = mkOption {
27 type = types.nullOr types.path;
29 Optional file containing a self-managed signing key to sign uploaded store paths.
34 compressionLevel = mkOption {
35 type = types.nullOr types.int;
36 description = "The compression level for ZSTD compression (between 0 and 16)";
41 type = types.nullOr types.int;
42 description = "Number of threads used for pushing store paths";
47 type = types.nullOr types.str;
49 description = "Cachix host to connect to";
54 description = "Enable verbose output";
58 package = mkPackageOption pkgs "cachix" { };
61 config = mkIf cfg.enable {
62 systemd.services.cachix-watch-store-agent = {
63 description = "Cachix watch store Agent";
64 wants = [ "network-online.target" ];
65 after = [ "network-online.target" ];
66 path = [ config.nix.package ];
67 wantedBy = [ "multi-user.target" ];
69 # allow to restart indefinitely
70 StartLimitIntervalSec = 0;
73 # don't put too much stress on the machine when restarting
75 # we don't want to kill children processes as those are deployments
77 Restart = "on-failure";
80 "cachix-token:${toString cfg.cachixTokenFile}"
82 ++ lib.optional (cfg.signingKeyFile != null) "signing-key:${toString cfg.signingKeyFile}";
86 command = [ "${cfg.package}/bin/cachix" ]
87 ++ (lib.optional cfg.verbose "--verbose") ++ (lib.optionals (cfg.host != null) [ "--host" cfg.host ])
88 ++ [ "watch-store" ] ++ (lib.optionals (cfg.compressionLevel != null) [ "--compression-level" (toString cfg.compressionLevel) ])
89 ++ (lib.optionals (cfg.jobs != null) [ "--jobs" (toString cfg.jobs) ]) ++ [ cfg.cacheName ];
92 export CACHIX_AUTH_TOKEN="$(<"$CREDENTIALS_DIRECTORY/cachix-token")"
93 ${lib.optionalString (cfg.signingKeyFile != null) ''export CACHIX_SIGNING_KEY="$(<"$CREDENTIALS_DIRECTORY/signing-key")"''}
94 ${lib.escapeShellArgs command}