From 722afdc5eaf73d9a6041ea2df6d8b6c8c99be0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= <nicolas.jeannerod@moduscreate.com> Date: Fri, 21 Feb 2025 12:36:07 +0100 Subject: [PATCH] Expose a NixOS configuration for each VM in infra --- infra/flake-part.nix | 55 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) 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; }