2022-01-14 14:54:42 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.cachix-agent;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
meta.maintainers = [ lib.maintainers.domenkozar ];
|
|
|
|
|
|
|
|
options.services.cachix-agent = {
|
2024-12-29 21:50:39 +01:00
|
|
|
enable = lib.mkEnableOption "Cachix Deploy Agent: https://docs.cachix.org/deploy/";
|
2022-01-14 14:54:42 +01:00
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-01-14 14:54:42 +01:00
|
|
|
description = "Agent name, usually same as the hostname";
|
|
|
|
default = config.networking.hostName;
|
|
|
|
defaultText = "config.networking.hostName";
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
verbose = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-06-30 09:56:28 -05:00
|
|
|
description = "Enable verbose output";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
profile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2022-01-14 14:54:42 +01:00
|
|
|
default = null;
|
|
|
|
description = "Profile name, defaults to 'system' (NixOS).";
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
host = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2022-09-11 21:07:45 +01:00
|
|
|
default = null;
|
|
|
|
description = "Cachix uri to use.";
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
package = lib.mkPackageOption pkgs "cachix" { };
|
2022-01-14 14:54:42 +01:00
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
credentialsFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2022-01-14 14:54:42 +01:00
|
|
|
default = "/etc/cachix-agent.token";
|
|
|
|
description = ''
|
|
|
|
Required file that needs to contain CACHIX_AGENT_TOKEN=...
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:39 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
2022-01-14 14:54:42 +01:00
|
|
|
systemd.services.cachix-agent = {
|
|
|
|
description = "Cachix Deploy Agent";
|
2023-10-03 22:21:50 -07:00
|
|
|
wants = [ "network-online.target" ];
|
2022-01-18 16:49:18 +01:00
|
|
|
after = [ "network-online.target" ];
|
2022-01-14 14:54:42 +01:00
|
|
|
path = [ config.nix.package ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2022-06-29 17:17:35 -05:00
|
|
|
|
2022-07-13 09:15:44 -05:00
|
|
|
# Cachix requires $USER to be set
|
|
|
|
environment.USER = "root";
|
|
|
|
|
|
|
|
# don't stop the service if the unit disappears
|
2022-06-29 17:17:35 -05:00
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
|
2022-01-14 14:54:42 +01:00
|
|
|
serviceConfig = {
|
2022-07-13 09:15:44 -05:00
|
|
|
# we don't want to kill children processes as those are deployments
|
|
|
|
KillMode = "process";
|
2022-12-27 12:24:01 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 5;
|
2022-01-14 14:54:42 +01:00
|
|
|
EnvironmentFile = cfg.credentialsFile;
|
2022-09-11 21:07:45 +01:00
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/cachix ${lib.optionalString cfg.verbose "--verbose"} ${
|
|
|
|
lib.optionalString (cfg.host != null) "--host ${cfg.host}"
|
|
|
|
} \
|
2024-12-29 21:50:39 +01:00
|
|
|
deploy agent ${cfg.name} ${lib.optionalString (cfg.profile != null) cfg.profile}
|
2022-09-11 21:07:45 +01:00
|
|
|
'';
|
2022-01-14 14:54:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|