{ inputs, lib, ... }: let inherit (lib) mkOption evalModules; inherit (lib.attrsets) genAttrs; ## Given a machine's name, make a resource module, except for its missing ## provider. (Depending on the use of that resource, we will provide a ## different one.) makeResourceModule = vmName: { _module.args = { inherit inputs; }; imports = [ ./common/resource.nix (./. + "/${vmName}") ]; fediversityVm.name = vmName; }; ## Given a list of machine names, make a deployment with those machines' ## configurations as resources makeDeployment = vmNames: { providers, ... }: { providers.local = inputs.nixops4.modules.nixops4Provider.local; resources = genAttrs vmNames (vmName: { type = providers.local.exec; imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos (makeResourceModule vmName) ]; }); }; makeDeployment' = vmName: makeDeployment [ vmName ]; nixops4ResourceNixosMockOptions = { ## NOTE: We allow the use of a few options from ## `inputs.nixops4-nixos.modules.nixops4Resource.nixos` such that we can ## reuse modules that make use of them. ## ## REVIEW: We can probably do much better and cleaner. On the other hand, ## this is only needed to expose NixOS configurations for provisioning ## purposes, and eventually all of this should be handled by NixOps4. options = { nixos.module = mkOption { }; # NOTE: not just `nixos` otherwise merging will go wrong nixpkgs = mkOption { }; ssh = mkOption { }; }; }; makeResourceConfig = vmName: (evalModules { modules = [ nixops4ResourceNixosMockOptions (makeResourceModule vmName) ]; }).config; ## Given a VM name, make a NixOS configuration for this machine. makeConfiguration = vmName: inputs.nixpkgs.lib.nixosSystem { modules = [ (makeResourceConfig vmName).nixos.module ]; }; makeVmOptions = vmName: { inherit ((makeResourceConfig vmName).fediversityVm) proxmox vmId sockets cores memory hostPublicKey unsafeHostPrivateKey ; }; machines = [ "vm02116" "vm02179" "vm02186" "vm02187" "fedi200" "fedi201" ]; testMachines = [ "test01" "test02" "test03" "test04" "test05" ]; in { flake.lib.makeInstallerIso = import ./makeInstallerIso.nix; ## - Each normal or test machine gets a NixOS configuration. ## - Each normal or test machine gets a VM options entry. ## - Each normal machine gets a deployment. ## - We add a “default” deployment with all normal machines. ## - We add a “test” deployment with all test machines. nixops4Deployments = genAttrs machines makeDeployment' // { default = makeDeployment machines; test = makeDeployment testMachines; }; flake.nixosConfigurations = genAttrs (machines ++ testMachines) makeConfiguration; flake.vmOptions = genAttrs (machines ++ testMachines) makeVmOptions; }