From 6761cb32f2cb15b78a5e1cad80eee16d3c378a5a Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 29 Jul 2025 23:13:10 -0500 Subject: [PATCH] Move big 3 to run both Runners --- hosts/isaiah/default.nix | 13 +---- hosts/jeremiah/default.nix | 19 ++----- hosts/zeke/default.nix | 3 +- hosts/zeke/virt.nix | 60 +-------------------- modules/nixos/default.nix | 1 + modules/nixos/gitlab-runner.nix | 96 +++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 87 deletions(-) create mode 100644 modules/nixos/gitlab-runner.nix diff --git a/hosts/isaiah/default.nix b/hosts/isaiah/default.nix index 9b9825d..a6d4645 100644 --- a/hosts/isaiah/default.nix +++ b/hosts/isaiah/default.nix @@ -42,6 +42,7 @@ }; tailscale.enable = true; remote-builder.enable = true; + runner.enable = true; }; fileSystems = { @@ -84,16 +85,4 @@ settings.PermitRootLogin = "yes"; }; }; - - virtualisation = { - libvirtd = { - enable = true; - allowedBridges = [ - "br0" - "virbr0" - ]; - onBoot = "ignore"; # only restart VMs labeled 'autostart' - qemu.ovmf.enable = true; - }; - }; } diff --git a/hosts/jeremiah/default.nix b/hosts/jeremiah/default.nix index d4dcfeb..8094977 100644 --- a/hosts/jeremiah/default.nix +++ b/hosts/jeremiah/default.nix @@ -82,6 +82,10 @@ in }; tailscale.enable = true; remote-builder.enable = true; + runner = { + enable = true; + threads = 3; + }; }; networking = { @@ -113,21 +117,6 @@ in age.secrets.runner-reg.file = ../../secrets/gitlab/nixos-qemu-shell.age; services = { - gitlab-runner = { - enable = true; - settings.concurrent = 3; - services = { - shell = { - executor = "shell"; - limit = 7; - authenticationTokenConfigFile = config.age.secrets.runner-reg.path; - environmentVariables = { - EFI_DIR = "${pkgs.OVMF.fd}/FV/"; - STORAGE_URL = "s3.thehellings.lan:9000"; - }; - }; - }; - }; proxmox-ve = { enable = true; ipAddress = (builtins.elemAt config.networking.interfaces.br0.ipv4.addresses 0).address; diff --git a/hosts/zeke/default.nix b/hosts/zeke/default.nix index e0cddf6..f1a8908 100644 --- a/hosts/zeke/default.nix +++ b/hosts/zeke/default.nix @@ -16,13 +16,14 @@ boot.extraModulePackages = [ config.boot.kernelPackages.v4l2loopback ]; greg = { - tailscale.enable = true; kubernetes = { enable = true; vipInterface = "enp12s0"; priority = 253; }; remote-builder.enable = true; + runner.enable = true; + tailscale.enable = true; }; hardware = { diff --git a/hosts/zeke/virt.nix b/hosts/zeke/virt.nix index 8a7d448..d3408d4 100644 --- a/hosts/zeke/virt.nix +++ b/hosts/zeke/virt.nix @@ -1,15 +1,10 @@ { - config, lib, pkgs, ... }: let - environmentVariables = { - EFI_DIR = "${pkgs.OVMF.fd}/FV/"; - STORAGE_URL = "s3.thehellings.lan:9000"; - }; passthru = [ "1002:164e" # Raphael - embedded GPU "1002:1640" # Rembrandt - Audio @@ -18,41 +13,7 @@ let ]; in { - specialisation = { - vbox.configuration = { - users.extraGroups.vboxusers.members = [ "greg" ]; - - virtualisation = { - virtualbox.host = { - enable = true; - enableExtensionPack = true; - }; - }; - - services.gitlab-runner.services = lib.mkForce { - vbox = { - inherit environmentVariables; - authenticationTokenConfigFile = config.age.secrets.vbox.path; - executor = "shell"; - limit = 5; - }; - }; - - systemd.services.gitlab-runner = { - serviceConfig = { - DevicePolicy = lib.mkForce "auto"; - User = "root"; - DynamicUser = lib.mkForce false; - }; - }; - }; - }; - - age.secrets = { - qemu.file = ../../secrets/gitlab/nixos-qemu-shell.age; - vbox.file = ../../secrets/gitlab/nixos-vbox-shell.age; - }; - + greg.runner.enable = true; # These options enable sharing of the GPU with the VM boot = { # Order matters here, to prevent the AMD driver from getting to the driver before @@ -77,17 +38,6 @@ in hardware.graphics.enable = true; - services.gitlab-runner = { - enable = true; - settings.concurrent = 5; - services.qemu = { - inherit environmentVariables; - executor = "shell"; - limit = 5; - authenticationTokenConfigFile = config.age.secrets.qemu.path; - }; - }; - systemd.services = { "libvirt-nosleep@" = { description = "Prevent sleep while %i is running"; @@ -98,14 +48,6 @@ in ''; }; }; - - gitlab-runner = { - serviceConfig = { - DevicePolicy = lib.mkForce "auto"; - User = "root"; - DynamicUser = lib.mkForce false; - }; - }; }; virtualisation = { diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index d1185e0..4be84b2 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -8,6 +8,7 @@ ./ceph.nix ./container.nix ./db.nix + ./gitlab-runner.nix ./gnome.nix ./home.nix ./kde.nix diff --git a/modules/nixos/gitlab-runner.nix b/modules/nixos/gitlab-runner.nix new file mode 100644 index 0000000..c190ac1 --- /dev/null +++ b/modules/nixos/gitlab-runner.nix @@ -0,0 +1,96 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.greg.runner; + environmentVariables = { + EFI_DIR = "${pkgs.OVMF.fd}/FV/"; + STORAGE_URL = "s3.thehellings.lan:9000"; + }; +in +{ + options.greg.runner = { + enable = lib.mkEnableOption "Enable as a gitlab-runner with both libvirt and virtualbox"; + + threads = lib.mkOption { + default = 5; + type = lib.types.int; + description = "The maximum number of concurrent jobs"; + }; + }; + + config = lib.mkIf cfg.enable { + # Shared configurations + age.secrets = { + qemu.file = ../../secrets/gitlab/nixos-qemu-shell.age; + vbox.file = ../../secrets/gitlab/nixos-vbox-shell.age; + }; + + # Defaults to running libvirt support + services.gitlab-runner = { + enable = true; + settings.concurrent = cfg.threads; + services.qemu = { + inherit environmentVariables; + executor = "shell"; + limit = cfg.threads; + authenticationTokenConfigFile = config.age.secrets.qemu.path; + }; + }; + + systemd.services.gitlab-runner = { + serviceConfig = { + DevicePolicy = lib.mkForce "auto"; + User = "root"; + DynamicUser = lib.mkForce false; + }; + }; + + virtualisation = { + libvirtd = { + enable = true; + allowedBridges = [ + "br0" + "virbr0" + ]; + onBoot = "ignore"; # only restart VMs labeled 'autostart' + qemu.ovmf.enable = true; + }; + }; + # Boot into this specialisation if you want to build vbox hosts + # with this box at that time + specialisation = { + vbox.configuration = { + users.extraGroups.vboxusers.members = [ "greg" ]; + + virtualisation = { + virtualbox.host = { + enable = true; + enableExtensionPack = true; + }; + }; + + services.gitlab-runner.services = lib.mkForce { + vbox = { + inherit environmentVariables; + authenticationTokenConfigFile = config.age.secrets.vbox.path; + executor = "shell"; + limit = 5; + }; + }; + + systemd.services.gitlab-runner = { + serviceConfig = { + DevicePolicy = lib.mkForce "auto"; + User = "root"; + DynamicUser = lib.mkForce false; + }; + }; + }; + }; + + }; +}