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.

81 lines
2.2 KiB
Nix
Raw Normal View History

2022-01-14 14:54:42 +01:00
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.cachix-agent;
in {
meta.maintainers = [ lib.maintainers.domenkozar ];
options.services.cachix-agent = {
enable = mkEnableOption (lib.mdDoc "Cachix Deploy Agent: https://docs.cachix.org/deploy/");
2022-01-14 14:54:42 +01:00
name = mkOption {
type = types.str;
description = lib.mdDoc "Agent name, usually same as the hostname";
2022-01-14 14:54:42 +01:00
default = config.networking.hostName;
defaultText = "config.networking.hostName";
};
2022-06-30 09:56:28 -05:00
verbose = mkOption {
type = types.bool;
description = lib.mdDoc "Enable verbose output";
2022-06-30 09:56:28 -05:00
default = false;
};
2022-01-14 14:54:42 +01:00
profile = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc "Profile name, defaults to 'system' (NixOS).";
2022-01-14 14:54:42 +01:00
};
2022-09-11 21:07:45 +01:00
host = mkOption {
type = types.nullOr types.str;
2022-09-11 21:07:45 +01:00
default = null;
description = lib.mdDoc "Cachix uri to use.";
};
2022-01-14 14:54:42 +01:00
package = mkOption {
type = types.package;
default = pkgs.cachix;
defaultText = literalExpression "pkgs.cachix";
description = lib.mdDoc "Cachix Client package to use.";
2022-01-14 14:54:42 +01:00
};
credentialsFile = mkOption {
type = types.path;
default = "/etc/cachix-agent.token";
description = lib.mdDoc ''
2022-01-14 14:54:42 +01:00
Required file that needs to contain CACHIX_AGENT_TOKEN=...
'';
};
};
config = mkIf cfg.enable {
systemd.services.cachix-agent = {
description = "Cachix Deploy Agent";
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}"} \
2023-03-19 21:44:31 +01:00
deploy agent ${cfg.name} ${optionalString (cfg.profile != null) cfg.profile}
2022-09-11 21:07:45 +01:00
'';
2022-01-14 14:54:42 +01:00
};
};
};
}