109 lines
3.3 KiB
Nix
109 lines
3.3 KiB
Nix
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}:
|
|
with lib;
|
|
let
|
|
cfg = config.features.gitlab-runner;
|
|
|
|
configuration = {
|
|
services.gitlab-runner = {
|
|
enable = true;
|
|
# NOTE(mrtz): Periodically prune gitlab runner's Docker resources
|
|
clear-docker-cache = {
|
|
enable = true;
|
|
dates = "monthly";
|
|
};
|
|
settings = {
|
|
concurrent = 16;
|
|
};
|
|
services = {
|
|
nix = {
|
|
# NOTE(simkir): This must be uploaded to the host after you've
|
|
# registered a runner in gitlab.
|
|
registrationConfigFile = "/root/gitlab/gitlab-runner-registration";
|
|
|
|
# TODO(mrtz): https://archives.docs.gitlab.com/17.0/ee/ci/runners/new_creation_workflow/
|
|
# authenticationTokenConfigFile = "";
|
|
|
|
requestConcurrency = 3;
|
|
|
|
dockerImage = "alpine";
|
|
dockerVolumes = [
|
|
# The items are ro because we write to the store via the daemon
|
|
"/nix/store:/nix/store:ro"
|
|
"/nix/var/nix/db:/nix/var/nix/db:ro"
|
|
"/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket:ro"
|
|
];
|
|
dockerDisableCache = true;
|
|
registrationFlags = [
|
|
"--docker-pull-policy=if-not-present"
|
|
"--docker-allowed-pull-policies=if-not-present"
|
|
"--docker-allowed-pull-policies=always"
|
|
];
|
|
|
|
preBuildScript = pkgs.writeScript "setup-container" ''
|
|
mkdir -p -m 0755 /nix/var/log/nix/drvs
|
|
mkdir -p -m 0755 /nix/var/nix/gcroots
|
|
mkdir -p -m 0755 /nix/var/nix/profiles
|
|
mkdir -p -m 0755 /nix/var/nix/temproots
|
|
mkdir -p -m 0755 /nix/var/nix/userpool
|
|
mkdir -p -m 1777 /nix/var/nix/gcroots/per-user
|
|
mkdir -p -m 1777 /nix/var/nix/profiles/per-user
|
|
mkdir -p -m 0755 /nix/var/nix/profiles/per-user/root
|
|
mkdir -p -m 0700 "$HOME/.nix-defexpr"
|
|
|
|
mkdir -p /etc/nix
|
|
cat << EOF > /etc/nix/nix.conf
|
|
experimental-features = nix-command flakes pipe-operators
|
|
EOF
|
|
|
|
. ${pkgs.nix}/etc/profile.d/nix-daemon.sh
|
|
${pkgs.nix}/bin/nix-channel --add https://nixos.org/channels/nixos-25.05 nixpkgs
|
|
${pkgs.nix}/bin/nix-channel --update nixpkgs
|
|
'';
|
|
|
|
environmentVariables = {
|
|
ENV = "/etc/profile";
|
|
USER = "root";
|
|
NIX_REMOTE = "daemon";
|
|
# Taken from https://cobalt.rocks/posts/nix-gitlab/
|
|
PATH =
|
|
(pkgs.lib.strings.makeSearchPathOutput "bin" "bin" (
|
|
with pkgs;
|
|
[
|
|
gnugrep
|
|
findutils
|
|
coreutils
|
|
curl
|
|
nix
|
|
openssh
|
|
bash
|
|
git
|
|
skopeo
|
|
]
|
|
))
|
|
+ ":/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/local/sbin:/nix/var/nix/profiles/default/sbin:/bin:/sbin:/usr/bin:/usr/sbin";
|
|
};
|
|
|
|
tagList = [ "nix" ];
|
|
};
|
|
};
|
|
};
|
|
systemd.services.gitlab-runner = {
|
|
after = [ "podman.service" ];
|
|
requires = [ "podman.service" ];
|
|
serviceConfig.SupplementaryGroups = [ "podman" ];
|
|
};
|
|
};
|
|
in
|
|
{
|
|
options.features.gitlab-runner = {
|
|
enable = mkEnableOption "Enable Gitlab runner service";
|
|
};
|
|
|
|
config = mkIf cfg.enable configuration;
|
|
}
|