From 98f98a8895fd8eb1a7da12d64100ee512fda3910 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 4 May 2025 16:20:00 -0400 Subject: [PATCH] Centralize the config for buildMachines. --- nix/configuration/configuration.nix | 1 + .../hosts/odo/distributed_build.nix | 51 ++------- .../hosts/quark/distributed_build.nix | 27 +---- .../roles/distributed_build/default.nix | 104 ++++++++++++++++++ 4 files changed, 122 insertions(+), 61 deletions(-) create mode 100644 nix/configuration/roles/distributed_build/default.nix diff --git a/nix/configuration/configuration.nix b/nix/configuration/configuration.nix index 1117112..5a1b58f 100644 --- a/nix/configuration/configuration.nix +++ b/nix/configuration/configuration.nix @@ -16,6 +16,7 @@ ./roles/boot ./roles/chromecast ./roles/chromium + ./roles/distributed_build ./roles/docker ./roles/ecc ./roles/emacs diff --git a/nix/configuration/hosts/odo/distributed_build.nix b/nix/configuration/hosts/odo/distributed_build.nix index ee3403b..46dccfc 100644 --- a/nix/configuration/hosts/odo/distributed_build.nix +++ b/nix/configuration/hosts/odo/distributed_build.nix @@ -9,48 +9,19 @@ config = lib.mkMerge [ { - nix.distributedBuilds = true; - nix.buildMachines = [ - { - hostName = "hydra"; - sshUser = "nixworker"; - systems = [ - "x86_64-linux" - # "aarch64-linux" - ]; - maxJobs = 1; + me.distributed_build.enable = true; + me.distributed_build.machines.hydra = { + enable = true; + additional_config = { speedFactor = 2; - supportedFeatures = [ - # "nixos-test" - "benchmark" - "big-parallel" - # "kvm" - "gccarch-x86-64-v3" - "gccarch-x86-64-v4" - "gccarch-znver4" - ]; - } - { - hostName = "quark"; - sshUser = "nixworker"; - systems = [ - "x86_64-linux" - # "aarch64-linux" - ]; - maxJobs = 1; + }; + }; + me.distributed_build.machines.quark = { + enable = true; + additional_config = { speedFactor = 2; - supportedFeatures = [ - # "nixos-test" - "benchmark" - "big-parallel" - # "kvm" - "gccarch-x86-64-v3" - "gccarch-x86-64-v4" - "gccarch-znver4" - "gccarch-znver5" - ]; - } - ]; + }; + }; } ]; } diff --git a/nix/configuration/hosts/quark/distributed_build.nix b/nix/configuration/hosts/quark/distributed_build.nix index 9a3c31b..942c265 100644 --- a/nix/configuration/hosts/quark/distributed_build.nix +++ b/nix/configuration/hosts/quark/distributed_build.nix @@ -9,28 +9,13 @@ config = lib.mkMerge [ { - nix.distributedBuilds = true; - nix.buildMachines = [ - { - hostName = "hydra"; - sshUser = "nixworker"; - systems = [ - "x86_64-linux" - # "aarch64-linux" - ]; - maxJobs = 1; + me.distributed_build.enable = true; + me.distributed_build.machines.hydra = { + enable = true; + additional_config = { speedFactor = 2; - supportedFeatures = [ - # "nixos-test" - "benchmark" - "big-parallel" - # "kvm" - "gccarch-x86-64-v3" - "gccarch-x86-64-v4" - "gccarch-znver4" - ]; - } - ]; + }; + }; } ]; } diff --git a/nix/configuration/roles/distributed_build/default.nix b/nix/configuration/roles/distributed_build/default.nix new file mode 100644 index 0000000..f97b34e --- /dev/null +++ b/nix/configuration/roles/distributed_build/default.nix @@ -0,0 +1,104 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + make_machine_config = name: { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = "Whether we want to use the ${name} machine during distributed builds."; + }; + + additional_config = lib.mkOption { + type = lib.types.attrs; + default = { }; + example = lib.literalExpression { + speedFactor = 2; + }; + description = "Additional config values for the buildMachines entry. For example, speedFactor."; + }; + }; +in +{ + imports = [ ]; + + options.me = { + distributed_build.enable = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = "Whether we want to use multiple machines to perform a nixos-rebuild."; + }; + + distributed_build.machines.hydra = make_machine_config "hydra"; + distributed_build.machines.quark = make_machine_config "quark"; + }; + + config = lib.mkIf config.me.distributed_build.enable ( + lib.mkMerge [ + { + nix.distributedBuilds = true; + } + (lib.mkIf config.me.distributed_build.machines.hydra.enable { + nix.buildMachines = [ + ( + { + hostName = "hydra"; + sshUser = "nixworker"; + # sshKey = ""; + # publicHostKey = ""; + systems = [ + "x86_64-linux" + # "aarch64-linux" + ]; + maxJobs = 1; + supportedFeatures = [ + # "nixos-test" + "benchmark" + "big-parallel" + # "kvm" + "gccarch-x86-64-v3" + "gccarch-x86-64-v4" + "gccarch-znver4" + ]; + } + // config.me.distributed_build.machines.hydra.additional_config + ) + ]; + }) + (lib.mkIf config.me.distributed_build.machines.quark.enable { + nix.buildMachines = [ + ( + { + hostName = "quark"; + sshUser = "nixworker"; + # sshKey = ""; + # publicHostKey = ""; + systems = [ + "x86_64-linux" + # "aarch64-linux" + ]; + maxJobs = 1; + supportedFeatures = [ + # "nixos-test" + "benchmark" + "big-parallel" + # "kvm" + "gccarch-x86-64-v3" + "gccarch-x86-64-v4" + "gccarch-znver4" + "gccarch-znver5" + ]; + } + // config.me.distributed_build.machines.quark.additional_config + ) + ]; + }) + ] + ); +}