Expose a NixOS configuration for each VM in infra

This commit is contained in:
Nicolas Jeannerod 2025-02-21 12:36:07 +01:00
parent df78965bf4
commit 722afdc5ea
Signed by: Niols
GPG key ID: 35DB9EC8886E1CB8

View file

@ -5,8 +5,14 @@
}: }:
let let
inherit (lib) attrValues concatLists mapAttrs; inherit (lib)
inherit (lib.attrsets) genAttrs; attrValues
concatLists
mapAttrs
mkOption
evalModules
;
inherit (lib.attrsets) concatMapAttrs genAttrs;
addDefaultDeployment = addDefaultDeployment =
deployments: deployments // { default = concatLists (attrValues deployments); }; deployments: deployments // { default = concatLists (attrValues deployments); };
@ -35,11 +41,39 @@ let
} }
); );
in nixops4ResourceNixosMockOptions = {
{ ## NOTE: We allow the use of a few options from
flake.lib.makeInstallerIso = import ./makeInstallerIso.nix; ## `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 = [ git = [
"vm02116" "vm02116"
"fedi300" "fedi300"
@ -49,5 +83,12 @@ in
"vm02179" "vm02179"
"vm02186" "vm02186"
]; ];
}); };
in
{
flake.lib.makeInstallerIso = import ./makeInstallerIso.nix;
nixops4Deployments = makeDeployments (addDefaultDeployment machines);
flake.nixosConfigurations = makeConfigurations machines;
} }