/
cachix-agent.nix
78 lines (65 loc) · 1.87 KB
/
cachix-agent.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.cachix-agent;
in {
options.services.cachix-agent = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable to run Cachix Agent as a system service.
Read [Cachix Deploy](https://docs.cachix.org/deploy/) documentation for more information.
'';
};
name = mkOption {
type = types.str;
default = config.networking.hostName;
description = ''
Agent name, usually the same as the hostname.
'';
};
package = mkOption {
description = ''
Package containing cachix executable.
'';
type = types.package;
default = pkgs.cachix;
defaultText = literalExpression "pkgs.cachix";
};
credentialsFile = mkOption {
type = types.path;
default = "/etc/cachix-agent.token";
description = ''
Required file that needs to contain:
export CACHIX_AGENT_TOKEN=...
'';
};
logFile = mkOption {
type = types.nullOr types.path;
default = "/var/log/cachix-agent.log";
description = "Absolute path to log all stderr and stdout";
};
};
config = mkIf cfg.enable {
launchd.daemons.cachix-agent = {
script = ''
. ${cfg.credentialsFile}
exec ${cfg.package}/bin/cachix deploy agent ${cfg.name}
'';
path = [ config.nix.package pkgs.coreutils ];
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
];
};
};
}