One deployment per machine; bundle test machines

This commit is contained in:
Nicolas Jeannerod 2025-02-24 18:48:05 +01:00
parent bc8ad08228
commit f6960010cd
Signed by: Niols
GPG key ID: 35DB9EC8886E1CB8
2 changed files with 58 additions and 86 deletions

View file

@ -96,23 +96,6 @@ nixops4 apply
See `infra/proxmox-remove.sh --help`.
## Deployments
default
: Contains everything
`git`
: Machines hosting our Git infrastructure, eg. Forgejo and its actions runners
`web`
: Machines hosting our online content, eg. the website or the wiki
`other`
: Machines without a specific purpose
`hans`
: Testing machines for Hans's work
## Machines
These machines are hosted on the Procolix Proxmox instance,

View file

@ -5,18 +5,12 @@
}:
let
inherit (lib)
attrValues
concatLists
mapAttrs
mkOption
evalModules
;
inherit (lib.attrsets) concatMapAttrs genAttrs;
addDefaultDeployment =
deployments: deployments // { default = concatLists (attrValues deployments); };
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 = [
@ -26,8 +20,10 @@ let
fediversityVm.name = vmName;
};
makeDeployments = mapAttrs (
_: vmNames:
## 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;
@ -38,8 +34,8 @@ let
(makeResourceModule vmName)
];
});
}
);
};
makeDeployment' = vmName: makeDeployment [ vmName ];
nixops4ResourceNixosMockOptions = {
## NOTE: We allow the use of a few options from
@ -65,65 +61,58 @@ let
];
}).config;
makeConfigurations = concatMapAttrs (
_: vmNames:
genAttrs vmNames (
vmName:
inputs.nixpkgs.lib.nixosSystem {
modules = [
(makeResourceConfig vmName).nixos.module
];
}
)
);
## Given a VM name, make a NixOS configuration for this machine.
makeConfiguration =
vmName:
inputs.nixpkgs.lib.nixosSystem {
modules = [
(makeResourceConfig vmName).nixos.module
];
};
makeVmOptions = concatMapAttrs (
_: vmNames:
genAttrs vmNames (vmName: {
inherit ((makeResourceConfig vmName).fediversityVm)
proxmox
vmId
sockets
cores
memory
hostPublicKey
unsafeHostPrivateKey
;
})
);
machines = {
git = [
"vm02116"
];
web = [ "vm02187" ];
other = [
"vm02179"
"vm02186"
];
hans = [
"fedi200"
];
kiara = [
"fedi201"
];
test = [
"test01"
"test02"
"test03"
"test04"
"test05"
];
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;
## REVIEW: It would probably make more sense to have the VM names as parent of
## the corresponding resource, NixOS configuration, and VM options, rather
## than the contrary.
nixops4Deployments = makeDeployments (addDefaultDeployment machines);
flake.nixosConfigurations = makeConfigurations machines;
flake.vmOptions = makeVmOptions machines;
## - 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;
}