1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-21 17:01:10 +03:00
nixpkgs/nixos/modules/services/system/cachix-agent/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.2 KiB
Nix
Raw Normal View History

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 = {
enable = lib.mkEnableOption "Cachix Deploy Agent: https://docs.cachix.org/deploy/";
2022-01-14 14:54:42 +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";
};
verbose = lib.mkOption {
type = lib.types.bool;
2022-06-30 09:56:28 -05:00
description = "Enable verbose output";
default = false;
};
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).";
};
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.";
};
package = lib.mkPackageOption pkgs "cachix" { };
2022-01-14 14:54:42 +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=...
'';
};
};
config = lib.mkIf cfg.enable {
2022-01-14 14:54:42 +01:00
systemd.services.cachix-agent = {
description = "Cachix Deploy Agent";
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
2022-01-14 14:54:42 +01:00
path = [ config.nix.package ];
wantedBy = [ "multi-user.target" ];
# Cachix requires $USER to be set
environment.USER = "root";
# don't stop the service if the unit disappears
unitConfig.X-StopOnRemoval = false;
2022-01-14 14:54:42 +01:00
serviceConfig = {
# 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}"
} \
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
};
};
};
}