2023-09-17 19:51:08 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
2024-05-30 13:59:20 +00:00
|
|
|
name = "gitlab_runner";
|
|
|
|
cfg = config.services.skynet."${name}";
|
2023-09-17 19:51:08 +00:00
|
|
|
in {
|
2023-06-17 18:37:06 +00:00
|
|
|
imports = [
|
|
|
|
];
|
|
|
|
|
2024-05-30 13:59:20 +00:00
|
|
|
options.services.skynet."${name}" = {
|
2023-06-17 18:37:06 +00:00
|
|
|
enable = mkEnableOption "Skynet Gitlab Runner";
|
|
|
|
|
|
|
|
runner = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
gitlab = mkOption {
|
|
|
|
default = "https://gitlab.skynet.ie";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
description = mkOption {
|
|
|
|
default = cfg.runner.name;
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
docker = {
|
|
|
|
image = mkOption {
|
2024-07-20 11:20:36 +00:00
|
|
|
default = "alpine:latest";
|
2023-06-17 18:37:06 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
cleanup_dates = mkOption {
|
|
|
|
# https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS
|
|
|
|
# it will use a lot of storage so clear it daily, may change to hourly if required
|
|
|
|
default = "daily";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
# https://search.nixos.org/options?from=0&size=50&sort=alpha_desc&type=packages&query=services.gitlab-runner.
|
2023-07-15 14:05:57 +00:00
|
|
|
environment.systemPackages = [
|
2023-09-17 19:51:08 +00:00
|
|
|
pkgs.gitlab-runner
|
2023-07-15 14:05:57 +00:00
|
|
|
];
|
2023-06-17 18:37:06 +00:00
|
|
|
|
2023-08-09 18:56:30 +00:00
|
|
|
age.secrets.runner_01_nix.file = ../secrets/gitlab/runners/runner01.age;
|
|
|
|
age.secrets.runner_02_general.file = ../secrets/gitlab/runners/runner02.age;
|
2023-06-17 18:37:06 +00:00
|
|
|
|
2023-07-25 07:17:38 +00:00
|
|
|
boot.kernel.sysctl."net.ipv4.ip_forward" = true; # 1
|
2023-11-20 20:53:39 +00:00
|
|
|
virtualisation.docker.enable = true;
|
2023-07-25 07:17:38 +00:00
|
|
|
|
2023-08-07 01:07:35 +00:00
|
|
|
# taken from https://github.com/NixOS/nixpkgs/issues/245365#issuecomment-1663854128
|
2023-09-17 19:51:08 +00:00
|
|
|
virtualisation.docker.listenOptions = ["/run/docker.sock" "127.0.0.1:2375"];
|
2023-08-07 01:07:35 +00:00
|
|
|
|
2023-06-17 18:37:06 +00:00
|
|
|
services.gitlab-runner = {
|
|
|
|
enable = true;
|
|
|
|
|
2023-11-20 20:53:39 +00:00
|
|
|
# clear-docker-cache = {
|
|
|
|
# enable = true;
|
|
|
|
# dates = cfg.runner.docker.cleanup_dates;
|
|
|
|
# };
|
2023-06-17 18:37:06 +00:00
|
|
|
|
|
|
|
services = {
|
|
|
|
# might make a function later to have multiple runners, might never need it though
|
2023-07-30 03:57:06 +00:00
|
|
|
runner_nix = {
|
2023-06-17 18:37:06 +00:00
|
|
|
cloneUrl = cfg.runner.gitlab;
|
2023-08-09 18:56:30 +00:00
|
|
|
description = "For Nix only";
|
2023-09-17 19:51:08 +00:00
|
|
|
registrationFlags = ["--docker-host" "tcp://127.0.0.1:2375"];
|
2023-08-09 18:56:30 +00:00
|
|
|
registrationConfigFile = config.age.secrets.runner_01_nix.path;
|
2023-06-17 18:37:06 +00:00
|
|
|
dockerImage = cfg.runner.docker.image;
|
2023-07-25 07:17:38 +00:00
|
|
|
|
|
|
|
# from https://nixos.wiki/wiki/Gitlab_runner
|
|
|
|
dockerVolumes = [
|
|
|
|
"/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;
|
|
|
|
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"
|
|
|
|
. ${pkgs.nix}/etc/profile.d/nix-daemon.sh
|
2024-07-20 11:20:36 +00:00
|
|
|
${pkgs.nix}/bin/nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
|
2023-07-25 07:17:38 +00:00
|
|
|
${pkgs.nix}/bin/nix-channel --update nixpkgs
|
2024-07-20 11:20:36 +00:00
|
|
|
${pkgs.nix}/bin/nix-env -i ${concatStringsSep " " (with pkgs; [lix cacert git openssh])}
|
|
|
|
nix --version
|
2023-07-25 07:17:38 +00:00
|
|
|
'';
|
|
|
|
environmentVariables = {
|
|
|
|
ENV = "/etc/profile";
|
|
|
|
USER = "root";
|
|
|
|
NIX_REMOTE = "daemon";
|
|
|
|
PATH = "/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/bin:/sbin:/usr/bin:/usr/sbin";
|
|
|
|
NIX_SSL_CERT_FILE = "/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
};
|
2023-09-17 19:51:08 +00:00
|
|
|
tagList = ["nix"];
|
2023-07-30 03:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
runner_general = {
|
|
|
|
cloneUrl = cfg.runner.gitlab;
|
2023-08-09 18:56:30 +00:00
|
|
|
description = "General Runner";
|
2023-09-17 19:51:08 +00:00
|
|
|
registrationFlags = ["--docker-host" "tcp://127.0.0.1:2375"];
|
2023-08-09 18:56:30 +00:00
|
|
|
registrationConfigFile = config.age.secrets.runner_02_general.path;
|
2023-07-30 03:57:06 +00:00
|
|
|
dockerImage = cfg.runner.docker.image;
|
2023-06-17 18:37:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-09-17 19:51:08 +00:00
|
|
|
}
|