1 { config, pkgs, lib, ... }:
6 cfg = config.services.cachix-agent;
8 meta.maintainers = [ lib.maintainers.domenkozar ];
10 options.services.cachix-agent = {
11 enable = mkEnableOption "Cachix Deploy Agent: https://docs.cachix.org/deploy/";
15 description = "Agent name, usually same as the hostname";
16 default = config.networking.hostName;
17 defaultText = "config.networking.hostName";
22 description = "Enable verbose output";
27 type = types.nullOr types.str;
29 description = "Profile name, defaults to 'system' (NixOS).";
33 type = types.nullOr types.str;
35 description = "Cachix uri to use.";
38 package = mkPackageOption pkgs "cachix" { };
40 credentialsFile = mkOption {
42 default = "/etc/cachix-agent.token";
44 Required file that needs to contain CACHIX_AGENT_TOKEN=...
49 config = mkIf cfg.enable {
50 systemd.services.cachix-agent = {
51 description = "Cachix Deploy Agent";
52 wants = [ "network-online.target" ];
53 after = ["network-online.target"];
54 path = [ config.nix.package ];
55 wantedBy = [ "multi-user.target" ];
57 # Cachix requires $USER to be set
58 environment.USER = "root";
60 # don't stop the service if the unit disappears
61 unitConfig.X-StopOnRemoval = false;
64 # we don't want to kill children processes as those are deployments
68 EnvironmentFile = cfg.credentialsFile;
70 ${cfg.package}/bin/cachix ${lib.optionalString cfg.verbose "--verbose"} ${lib.optionalString (cfg.host != null) "--host ${cfg.host}"} \
71 deploy agent ${cfg.name} ${optionalString (cfg.profile != null) cfg.profile}