1
0
Fork 0

Split machine definitions into subdirectories

This commit is contained in:
Nicolas Jeannerod 2025-02-25 11:50:46 +01:00
parent 3f9c174d97
commit c74145fe24
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8
24 changed files with 33 additions and 23 deletions

View file

@ -14,17 +14,19 @@ let
;
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 machine's name and whether it is a test VM, make a resource module,
## except for its missing provider. (Depending on the use of that resource, we
## will provide a different one.)
makeResourceModule =
{ vmName, isTestVm }:
{
_module.args = { inherit inputs; };
imports = [
./common/resource.nix
(if isTestVm then ./test-machines + "/${vmName}" else ./machines + "/${vmName}")
];
fediversityVm.name = vmName;
};
## Given a list of machine names, make a deployment with those machines'
## configurations as resources.
@ -37,7 +39,10 @@ let
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
(makeResourceModule vmName)
(makeResourceModule {
inherit vmName;
isTestVm = false;
})
];
});
};
@ -55,7 +60,10 @@ let
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
(makeResourceModule vmName)
(makeResourceModule {
inherit vmName;
isTestVm = false;
})
{ nixos.module = vmConfig; }
{ nixos.module = self.nixosModules.fediversity; }
];
@ -78,25 +86,25 @@ let
};
makeResourceConfig =
vmName:
vm:
(evalModules {
modules = [
nixops4ResourceNixosMockOptions
(makeResourceModule vmName)
(makeResourceModule vm)
];
}).config;
## Given a VM name, make a NixOS configuration for this machine.
makeConfiguration =
vmName:
isTestVm: vmName:
inputs.nixpkgs.lib.nixosSystem {
modules = [
(makeResourceConfig vmName).nixos.module
(makeResourceConfig { inherit vmName isTestVm; }).nixos.module
];
};
makeVmOptions = vmName: {
inherit ((makeResourceConfig vmName).fediversityVm)
makeVmOptions = isTestVm: vmName: {
inherit ((makeResourceConfig { inherit vmName isTestVm; }).fediversityVm)
proxmox
vmId
sockets
@ -206,8 +214,10 @@ in
default = makeDeployment machines;
test = makeTestDeployment testMachineConfigurations;
};
flake.nixosConfigurations = genAttrs (
machines ++ attrNames testMachineConfigurations
) makeConfiguration;
flake.vmOptions = genAttrs (machines ++ attrNames testMachineConfigurations) makeVmOptions;
flake.nixosConfigurations =
genAttrs machines (makeConfiguration false)
// genAttrs (attrNames testMachineConfigurations) (makeConfiguration true);
flake.vmOptions =
genAttrs machines (makeVmOptions false)
// genAttrs (attrNames testMachineConfigurations) (makeVmOptions true);
}