@@ -4,14 +4,6 @@ with lib;
6 cfg = config.services.buildkite-agent;
6 cfg = config.services.buildkite-agent;
7− configFile = pkgs.writeText "buildkite-agent.cfg"
11− meta-data="${cfg.meta-data}"
12− hooks-path="${cfg.package}/share/hooks"
13− build-path="${cfg.dataDir}"
@@ -39,10 +31,13 @@ in
39 type = types.listOf types.package;
31 type = types.listOf types.package;
42− token = mkOption {
34+ tokenPath = mkOption {
43− type = types.str;
35+ type = types.path;
44 description = ''
36 description = ''
45 The token from your Buildkite "Agents" page.
37 The token from your Buildkite "Agents" page.
39+ A run-time path to the token file, which is supposed to be provisioned
40+ outside of Nix store.
@@ -62,16 +57,22 @@ in
65− { privateKey = mkOption {
60+ { privateKeyPath = mkOption {
66− type = types.str;
61+ type = types.path;
67 description = ''
62 description = ''
68 Private agent key.
63 Private agent key.
65+ A run-time path to the key file, which is supposed to be provisioned
66+ outside of Nix store.
71− publicKey = mkOption {
69+ publicKeyPath = mkOption {
72− type = types.str;
70+ type = types.path;
73 description = ''
71 description = ''
74 Public agent key.
72 Public agent key.
74+ A run-time path to the key file, which is supposed to be provisioned
75+ outside of Nix store.
@@ -84,11 +85,15 @@ in
84 home = cfg.dataDir;
85 home = cfg.dataDir;
85 createHome = true;
86 createHome = true;
86 description = "Buildkite agent user";
87 description = "Buildkite agent user";
88+ extraGroups = [ "keys" ];
89 environment.systemPackages = [ cfg.package ];
91 environment.systemPackages = [ cfg.package ];
91 systemd.services.buildkite-agent =
93 systemd.services.buildkite-agent =
94+ let copy = x: target: perms:
95+ "cp -f ${x} ${target}; ${pkgs.coreutils}/bin/chmod ${toString perms} ${target}; ";
92 { description = "Buildkite Agent";
97 { description = "Buildkite Agent";
93 wantedBy = [ "multi-user.target" ];
98 wantedBy = [ "multi-user.target" ];
94 after = [ "network.target" ];
99 after = [ "network.target" ];
@@ -97,18 +102,26 @@ in
97 HOME = cfg.dataDir;
102 HOME = cfg.dataDir;
98 NIX_REMOTE = "daemon";
103 NIX_REMOTE = "daemon";
101− ${pkgs.coreutils}/bin/mkdir -m 0700 -p ${cfg.dataDir}/.ssh
103− echo "${cfg.openssh.privateKey}" > ${cfg.dataDir}/.ssh/id_rsa
104− ${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa
106− echo "${cfg.openssh.publicKey}" > ${cfg.dataDir}/.ssh/id_rsa.pub
106+ ## NB: maximum care is taken so that secrets (ssh keys and the CI token)
107+ ## don't end up in the Nix store.
109+ ${pkgs.coreutils}/bin/mkdir -m 0700 -p ${cfg.dataDir}/.ssh
110+ ${copy (toString cfg.openssh.privateKeyPath) "${cfg.dataDir}/.ssh/id_rsa" 600}
107− ${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa.pub
111+ ${copy (toString cfg.openssh.publicKeyPath) "${cfg.dataDir}/.ssh/id_rsa.pub" 600}
113+ cat > "${cfg.dataDir}/buildkite-agent.cfg" <<EOF
114+ token="$(cat ${toString cfg.tokenPath})"
116+ meta-data="${cfg.meta-data}"
117+ hooks-path="${pkgs.buildkite-agent}/share/hooks"
118+ build-path="${cfg.dataDir}/builds"
119+ bootstrap-script="${pkgs.buildkite-agent}/share/bootstrap.sh"
110 serviceConfig =
123 serviceConfig =
111− { ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config ${configFile}";
124+ { ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config /var/lib/buildkite-agent/buildkite-agent.cfg";
112 User = "buildkite-agent";
125 User = "buildkite-agent";
113 RestartSec = 5;
126 RestartSec = 5;
114 Restart = "on-failure";
127 Restart = "on-failure";
@@ -116,4 +129,9 @@ in
133+ (mkRenamedOptionModule [ "services" "buildkite-agent" "token" ] [ "services" "buildkite-agent" "tokenPath" ])
134+ (mkRenamedOptionModule [ "services" "buildkite-agent" "openssh" "privateKey" ] [ "services" "buildkite-agent" "openssh" "privateKeyPath" ])
135+ (mkRenamedOptionModule [ "services" "buildkite-agent" "openssh" "publicKey" ] [ "services" "buildkite-agent" "openssh" "publicKeyPath" ])