8 cfg = config.services.cachix-agent;
11 meta.maintainers = [ lib.maintainers.domenkozar ];
13 options.services.cachix-agent = {
14 enable = lib.mkEnableOption "Cachix Deploy Agent: https://docs.cachix.org/deploy/";
18 description = "Agent name, usually same as the hostname";
19 default = config.networking.hostName;
20 defaultText = "config.networking.hostName";
23 verbose = lib.mkOption {
24 type = lib.types.bool;
25 description = "Enable verbose output";
29 profile = lib.mkOption {
30 type = lib.types.nullOr lib.types.str;
32 description = "Profile name, defaults to 'system' (NixOS).";
36 type = lib.types.nullOr lib.types.str;
38 description = "Cachix uri to use.";
41 package = lib.mkPackageOption pkgs "cachix" { };
43 credentialsFile = lib.mkOption {
44 type = lib.types.path;
45 default = "/etc/cachix-agent.token";
47 Required file that needs to contain CACHIX_AGENT_TOKEN=...
52 config = lib.mkIf cfg.enable {
53 systemd.services.cachix-agent = {
54 description = "Cachix Deploy Agent";
55 wants = [ "network-online.target" ];
56 after = [ "network-online.target" ];
57 path = [ config.nix.package ];
58 wantedBy = [ "multi-user.target" ];
60 # Cachix requires $USER to be set
61 environment.USER = "root";
63 # don't stop the service if the unit disappears
64 unitConfig.X-StopOnRemoval = false;
67 # we don't want to kill children processes as those are deployments
71 EnvironmentFile = cfg.credentialsFile;
73 ${cfg.package}/bin/cachix ${lib.optionalString cfg.verbose "--verbose"} ${
74 lib.optionalString (cfg.host != null) "--host ${cfg.host}"
76 deploy agent ${cfg.name} ${lib.optionalString (cfg.profile != null) cfg.profile}