From 6256149a9075a00ce94047a301c6e47a39e102c1 Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Mon, 30 Jan 2023 11:46:50 -0800 Subject: [PATCH] feat: distributed builds module --- common/distributed.nix | 28 ----------------- modules/common/distributed.nix | 55 ++++++++++++++++++++++++++++++++++ systems/default.nix | 1 + systems/sumireko.nix | 2 ++ tree.nix | 5 ++++ 5 files changed, 63 insertions(+), 28 deletions(-) delete mode 100644 common/distributed.nix create mode 100644 modules/common/distributed.nix diff --git a/common/distributed.nix b/common/distributed.nix deleted file mode 100644 index 894e0e15..00000000 --- a/common/distributed.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ lib, config, inputs, ... }: let - inherit (lib.attrsets) mapAttrsToList; - inherit (lib.lists) optionals; - buildMachines = mapAttrsToList (name: config_: let - config = config_.config; - in { - hostName = "${config.networking.hostName}.inskip.me"; - sshUser = "deploy"; - systems = [ config.nixpkgs.system ] ++ optionals (config.nix.settings ? extra-platforms) config.nix.settings.extra-platforms; - maxJobs = 100; - speedFactor = 1; # TODO: provide adjustment factor - supportedFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; - } ) inputs.self.nixosConfigurations; - daiyousei = { - hostName = "daiyousei.inskip.me"; - sshUser = "root"; - system = "aarch64-linux"; - maxJobs = 100; - speedFactor = 1; - supportedFeatures = ["benchmark" "big-parallel" "kvm"]; - mandatoryFeatures = []; - }; -in { - nix = { - inherit buildMachines; - distributedBuilds = true; - }; -} diff --git a/modules/common/distributed.nix b/modules/common/distributed.nix new file mode 100644 index 00000000..824baa79 --- /dev/null +++ b/modules/common/distributed.nix @@ -0,0 +1,55 @@ +{ lib, config, inputs, ... }: let + # TODO: convert to nix-std + inherit (lib.attrsets) mapAttrsToList mapAttrs; + inherit (lib.lists) optionals; + inherit (lib.options) mkOption; + inherit (lib.types) int attrsOf submodule; + buildMachines = mapAttrsToList (name: extern_: let + extern = extern_.config; + in { + hostName = "${name}.inskip.me"; + sshUser = "deploy"; + systems = [ extern.nixpkgs.system ] ++ optionals (extern.nix.settings ? extra-platforms) extern.nix.settings.extra-platforms; + maxJobs = 100; + speedFactor = config.distributed.outputs.${name}; + supportedFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; + } ) (inputs.self.nixosConfigurations // inputs.self.darwinConfigurations); + daiyousei = { + hostName = "daiyousei.inskip.me"; + sshUser = "root"; + system = "aarch64-linux"; + maxJobs = 100; + speedFactor = 1; + supportedFeatures = ["benchmark" "big-parallel" "kvm"]; + mandatoryFeatures = []; + }; +in { + options.distributed = let + baseOptions = { + options.preference = mkOption { + type = int; + default = 1; + }; + }; + in baseOptions.options // { + systems = mkOption { + type = attrsOf (submodule baseOptions); + default = {}; + }; + outputs = mkOption { + type = attrsOf int; + default = {}; + }; + }; + config = { + distributed.outputs = mapAttrs (name: extern: extern.config.distributed.preference + + (if config.distributed.systems ? ${name} && config.distributed.systems.${name} ? preference then + config.distributed.systems.${name}.preference + else 0) + ) (inputs.self.nixosConfigurations // inputs.self.darwinConfigurations); + nix = { + inherit buildMachines; + distributedBuilds = true; + }; + }; +} diff --git a/systems/default.nix b/systems/default.nix index bde2307b..c3ea808c 100644 --- a/systems/default.nix +++ b/systems/default.nix @@ -71,6 +71,7 @@ .${string.toLower config.type}; modules = with tree; [ tree.modules.${config.folder} + tree.modules.common tree.${config.folder}.common tree.kat.user.${config.folder} common diff --git a/systems/sumireko.nix b/systems/sumireko.nix index c261f5d4..29e02fb9 100644 --- a/systems/sumireko.nix +++ b/systems/sumireko.nix @@ -7,6 +7,8 @@ _: let security.pam.enableSudoTouchIdAuth = true; + distributed.systems.renko.preference = 5; + homebrew = { brewPrefix = "/opt/homebrew/bin"; brews = [ diff --git a/tree.nix b/tree.nix index 0d8eee7f..163e3f57 100644 --- a/tree.nix +++ b/tree.nix @@ -35,6 +35,11 @@ "darwin/*".functor.enable = true; "kat/*".functor.enable = true; # Various modules + "modules/common" = { + functor = { + enable = true; + }; + }; "modules/nixos" = { functor = { enable = true;