8 cfg = config.services.cachix-watch-store;
12 lib.maintainers.jfroche
13 lib.maintainers.domenkozar
16 options.services.cachix-watch-store = {
17 enable = lib.mkEnableOption "Cachix Watch Store: https://docs.cachix.org";
19 cacheName = lib.mkOption {
21 description = "Cachix binary cache name";
24 cachixTokenFile = lib.mkOption {
25 type = lib.types.path;
27 Required file that needs to contain the cachix auth token.
31 signingKeyFile = lib.mkOption {
32 type = lib.types.nullOr lib.types.path;
34 Optional file containing a self-managed signing key to sign uploaded store paths.
39 compressionLevel = lib.mkOption {
40 type = lib.types.nullOr lib.types.int;
41 description = "The compression level for ZSTD compression (between 0 and 16)";
46 type = lib.types.nullOr lib.types.int;
47 description = "Number of threads used for pushing store paths";
52 type = lib.types.nullOr lib.types.str;
54 description = "Cachix host to connect to";
57 verbose = lib.mkOption {
58 type = lib.types.bool;
59 description = "Enable verbose output";
63 package = lib.mkPackageOption pkgs "cachix" { };
66 config = lib.mkIf cfg.enable {
67 systemd.services.cachix-watch-store-agent = {
68 description = "Cachix watch store Agent";
69 wants = [ "network-online.target" ];
70 after = [ "network-online.target" ];
71 path = [ config.nix.package ];
72 wantedBy = [ "multi-user.target" ];
74 # allow to restart indefinitely
75 StartLimitIntervalSec = 0;
78 # don't put too much stress on the machine when restarting
80 # we don't want to kill children processes as those are deployments
82 Restart = "on-failure";
85 "cachix-token:${toString cfg.cachixTokenFile}"
86 ] ++ lib.optional (cfg.signingKeyFile != null) "signing-key:${toString cfg.signingKeyFile}";
91 [ "${cfg.package}/bin/cachix" ]
92 ++ (lib.optional cfg.verbose "--verbose")
93 ++ (lib.optionals (cfg.host != null) [
98 ++ (lib.optionals (cfg.compressionLevel != null) [
100 (toString cfg.compressionLevel)
102 ++ (lib.optionals (cfg.jobs != null) [
106 ++ [ cfg.cacheName ];
109 export CACHIX_AUTH_TOKEN="$(<"$CREDENTIALS_DIRECTORY/cachix-token")"
110 ${lib.optionalString (
111 cfg.signingKeyFile != null
112 ) ''export CACHIX_SIGNING_KEY="$(<"$CREDENTIALS_DIRECTORY/signing-key")"''}
113 ${lib.escapeShellArgs command}