2022-10-27 17:08:14 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.cachix-agent;
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
|
|
|
options.services.cachix-agent = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable =
|
|
|
|
mkEnableOption "Cachix Deploy Agent: <https://docs.cachix.org/deploy/>";
|
2022-10-27 17:08:14 +00:00
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "The unique agent name.";
|
2022-10-27 17:08:14 +00:00
|
|
|
};
|
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
verbose = mkEnableOption "verbose output";
|
2022-10-27 17:08:14 +00:00
|
|
|
|
|
|
|
profile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "home-manager";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2022-10-27 17:08:14 +00:00
|
|
|
The Nix profile name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Cachix URI to use.";
|
2022-10-27 17:08:14 +00:00
|
|
|
};
|
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
package = mkPackageOption pkgs "cachix" { };
|
2022-10-27 17:08:14 +00:00
|
|
|
|
|
|
|
credentialsFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${config.xdg.configHome}/cachix-agent.token";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.xdg.configHome}/cachix-agent.token"'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2022-10-27 17:08:14 +00:00
|
|
|
Required file that needs to contain
|
2023-06-30 23:30:13 +00:00
|
|
|
`CACHIX_AGENT_TOKEN=...`.
|
2022-10-27 17:08:14 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.cachix-agent" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.user.services.cachix-agent = {
|
|
|
|
Unit.Description = "Cachix Deploy Agent";
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Environment = [
|
|
|
|
"PATH=${
|
|
|
|
if config.nix.enable && config.nix.package != null then
|
|
|
|
config.nix.package
|
|
|
|
else
|
|
|
|
pkgs.nix
|
|
|
|
}/bin"
|
|
|
|
];
|
|
|
|
EnvironmentFile = cfg.credentialsFile;
|
|
|
|
|
|
|
|
# We don't want to kill children processes as those are deployments.
|
|
|
|
KillMode = "process";
|
|
|
|
Restart = "on-failure";
|
|
|
|
ExecStart = escapeShellArgs ([ "${cfg.package}/bin/cachix" ]
|
|
|
|
++ optional cfg.verbose "--verbose"
|
|
|
|
++ optional (cfg.host != null) "--host ${cfg.host}"
|
|
|
|
++ [ "deploy" "agent" cfg.name ]
|
|
|
|
++ optional (cfg.profile != null) cfg.profile);
|
|
|
|
};
|
|
|
|
|
|
|
|
Install.WantedBy = [ "default.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|