Last active
June 2, 2017 00:56
-
-
Save cleverca22/bac360be90ca2fc11cfbae5c8a7be351 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
with lib; | |
let | |
cfg = config.services.gitlab-runner; | |
configFile = pkgs.writeText "config.toml" cfg.configText; | |
in | |
{ | |
options.services.gitlab-runner = { | |
enable = mkEnableOption "Gitlab Runner"; | |
configText = mkOption { | |
description = "Verbatim config.toml to use"; | |
}; | |
workDir = mkOption { | |
default = "/var/lib/gitlab-runner"; | |
type = types.path; | |
description = "The working directory used"; | |
}; | |
}; | |
config = mkIf cfg.enable { | |
systemd.services.gitlab-runner = { | |
path = with pkgs; [ bash ]; | |
description = "Gitlab Runner"; | |
after = [ "network.target" "docker.service" ]; | |
requires = [ "docker.service" ]; | |
wantedBy = [ "multi-user.target" ]; | |
preStart = '' | |
mkdir -pv ${cfg.workDir} | |
chown gitlab-runner:gitlab-runner ${cfg.workDir} | |
''; | |
serviceConfig = { | |
User = "gitlab-runner"; | |
PermissionsStartOnly = "true"; | |
ExecStart = ''${pkgs.gitlab-runner.bin}/bin/gitlab-runner run \ | |
--working-directory ${cfg.workDir} \ | |
--config ${configFile} \ | |
--service gitlab-runner \ | |
''; | |
}; | |
}; | |
users.extraUsers.gitlab-runner = { | |
group = "gitlab-runner"; | |
extraGroups = [ "docker" ]; | |
uid = config.ids.uids.gitlab-runner; | |
home = cfg.workDir; | |
createHome = true; | |
}; | |
users.extraGroups.gitlab-runner.gid = config.ids.gids.gitlab-runner; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment