diff --git a/infra/flake-part.nix b/infra/flake-part.nix index b4f10dc..a7c110f 100644 --- a/infra/flake-part.nix +++ b/infra/flake-part.nix @@ -5,8 +5,14 @@ }: let - inherit (lib) attrValues concatLists mapAttrs; - inherit (lib.attrsets) genAttrs; + inherit (lib) + attrValues + concatLists + mapAttrs + mkOption + evalModules + ; + inherit (lib.attrsets) concatMapAttrs genAttrs; addDefaultDeployment = deployments: deployments // { default = concatLists (attrValues deployments); }; @@ -35,11 +41,39 @@ let } ); -in -{ - flake.lib.makeInstallerIso = import ./makeInstallerIso.nix; + 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 { }; + }; + }; - nixops4Deployments = makeDeployments (addDefaultDeployment { + makeConfigurations = concatMapAttrs ( + _: vmNames: + genAttrs vmNames ( + vmName: + inputs.nixpkgs.lib.nixosSystem { + modules = [ + (evalModules { + modules = [ + nixops4ResourceNixosMockOptions + (makeResourceModule vmName) + ]; + }).config.nixos.module + ]; + } + ) + ); + + machines = { git = [ "vm02116" "fedi300" @@ -49,5 +83,12 @@ in "vm02179" "vm02186" ]; - }); + }; + +in +{ + flake.lib.makeInstallerIso = import ./makeInstallerIso.nix; + + nixops4Deployments = makeDeployments (addDefaultDeployment machines); + flake.nixosConfigurations = makeConfigurations machines; }