2022-01-11 15:15:25 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cachix-agent;
|
|
|
|
in {
|
|
|
|
options.services.cachix-agent = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = ''
|
2022-01-11 15:15:25 +00:00
|
|
|
Enable to run Cachix Agent as a system service.
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
Read [Cachix Deploy](https://docs.cachix.org/deploy/) documentation for more information.
|
2022-01-11 15:15:25 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = ''
|
2022-01-11 15:15:25 +00:00
|
|
|
Agent name, usually the same as the hostname.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
description = ''
|
2022-01-11 15:15:25 +00:00
|
|
|
Package containing cachix executable.
|
|
|
|
'';
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.cachix;
|
2022-02-23 22:09:52 +00:00
|
|
|
defaultText = literalExpression "pkgs.cachix";
|
2022-01-11 15:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
credentialsFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/etc/cachix-agent.token";
|
2024-04-14 21:02:32 +00:00
|
|
|
description = ''
|
2023-07-12 15:46:02 +00:00
|
|
|
Required file that needs to contain:
|
2023-07-12 14:11:49 +00:00
|
|
|
|
|
|
|
export CACHIX_AGENT_TOKEN=...
|
2022-01-11 15:15:25 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = "/var/log/cachix-agent.log";
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Absolute path to log all stderr and stdout";
|
2022-01-11 15:15:25 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
launchd.daemons.cachix-agent = {
|
|
|
|
script = ''
|
|
|
|
. ${cfg.credentialsFile}
|
|
|
|
|
|
|
|
exec ${cfg.package}/bin/cachix deploy agent ${cfg.name}
|
|
|
|
'';
|
|
|
|
|
2024-05-16 13:55:14 +00:00
|
|
|
path = [ config.nix.package pkgs.coreutils config.environment.systemPath ];
|
2022-01-11 15:15:25 +00:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
USER = "root";
|
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig.KeepAlive = true;
|
|
|
|
serviceConfig.RunAtLoad = true;
|
|
|
|
serviceConfig.ProcessType = "Interactive";
|
|
|
|
serviceConfig.StandardErrorPath = cfg.logFile;
|
|
|
|
serviceConfig.StandardOutPath = cfg.logFile;
|
|
|
|
serviceConfig.WatchPaths = [
|
|
|
|
cfg.credentialsFile
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|