nixos/buildkite-agent: add "user" option

This allows buildkite-agent to run as another user.

It'll still run builds from /var/lib/buildkite-agent and setup things in
there.
This commit is contained in:
Florian Klink 2020-01-19 21:19:35 +01:00
parent 5ed3474ca5
commit 8c6b1c3eaa

View File

@ -29,6 +29,8 @@ let
${concatStringsSep "\n" (mapAttrsToList mkHookEntry (filterAttrs (n: v: v != null) cfg.hooks))}
'';
defaultUser = "buildkite-agent";
in
{
@ -56,6 +58,15 @@ in
type = types.listOf types.package;
};
user = mkOption {
type = types.str;
default = defaultUser;
description = ''
Set this option when you want to run the buildkite agent as something else
than the default user "buildkite-agent".
'';
};
tokenPath = mkOption {
type = types.path;
description = ''
@ -185,14 +196,14 @@ in
};
config = mkIf config.services.buildkite-agent.enable {
users.users.buildkite-agent =
{ name = "buildkite-agent";
home = cfg.dataDir;
createHome = true;
description = "Buildkite agent user";
extraGroups = [ "keys" ];
isSystemUser = true;
};
users.users.buildkite-agent = mkIf (cfg.user == defaultUser) {
name = "buildkite-agent";
home = cfg.dataDir;
createHome = true;
description = "Buildkite agent user";
extraGroups = [ "keys" ];
isSystemUser = true;
};
environment.systemPackages = [ cfg.package ];
@ -230,7 +241,7 @@ in
serviceConfig =
{ ExecStart = "${cfg.package}/bin/buildkite-agent start --config /var/lib/buildkite-agent/buildkite-agent.cfg";
User = "buildkite-agent";
User = cfg.user;
RestartSec = 5;
Restart = "on-failure";
TimeoutSec = 10;