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`. 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 ## Machines
These machines are hosted on the Procolix Proxmox instance, These machines are hosted on the Procolix Proxmox instance,

View file

@ -5,18 +5,12 @@
}: }:
let let
inherit (lib) inherit (lib) mkOption evalModules;
attrValues inherit (lib.attrsets) genAttrs;
concatLists
mapAttrs
mkOption
evalModules
;
inherit (lib.attrsets) concatMapAttrs genAttrs;
addDefaultDeployment =
deployments: deployments // { default = concatLists (attrValues deployments); };
## 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: { makeResourceModule = vmName: {
_module.args = { inherit inputs; }; _module.args = { inherit inputs; };
imports = [ imports = [
@ -26,8 +20,10 @@ let
fediversityVm.name = vmName; fediversityVm.name = vmName;
}; };
makeDeployments = mapAttrs ( ## Given a list of machine names, make a deployment with those machines'
_: vmNames: ## configurations as resources
makeDeployment =
vmNames:
{ providers, ... }: { providers, ... }:
{ {
providers.local = inputs.nixops4.modules.nixops4Provider.local; providers.local = inputs.nixops4.modules.nixops4Provider.local;
@ -38,8 +34,8 @@ let
(makeResourceModule vmName) (makeResourceModule vmName)
]; ];
}); });
} };
); makeDeployment' = vmName: makeDeployment [ vmName ];
nixops4ResourceNixosMockOptions = { nixops4ResourceNixosMockOptions = {
## NOTE: We allow the use of a few options from ## NOTE: We allow the use of a few options from
@ -65,21 +61,16 @@ let
]; ];
}).config; }).config;
makeConfigurations = concatMapAttrs ( ## Given a VM name, make a NixOS configuration for this machine.
_: vmNames: makeConfiguration =
genAttrs vmNames (
vmName: vmName:
inputs.nixpkgs.lib.nixosSystem { inputs.nixpkgs.lib.nixosSystem {
modules = [ modules = [
(makeResourceConfig vmName).nixos.module (makeResourceConfig vmName).nixos.module
]; ];
} };
)
);
makeVmOptions = concatMapAttrs ( makeVmOptions = vmName: {
_: vmNames:
genAttrs vmNames (vmName: {
inherit ((makeResourceConfig vmName).fediversityVm) inherit ((makeResourceConfig vmName).fediversityVm)
proxmox proxmox
vmId vmId
@ -89,41 +80,39 @@ let
hostPublicKey hostPublicKey
unsafeHostPrivateKey unsafeHostPrivateKey
; ;
}) };
);
machines = { machines = [
git = [
"vm02116" "vm02116"
];
web = [ "vm02187" ];
other = [
"vm02179" "vm02179"
"vm02186" "vm02186"
]; "vm02187"
hans = [
"fedi200" "fedi200"
];
kiara = [
"fedi201" "fedi201"
]; ];
test = [
testMachines = [
"test01" "test01"
"test02" "test02"
"test03" "test03"
"test04" "test04"
"test05" "test05"
]; ];
};
in in
{ {
flake.lib.makeInstallerIso = import ./makeInstallerIso.nix; flake.lib.makeInstallerIso = import ./makeInstallerIso.nix;
## REVIEW: It would probably make more sense to have the VM names as parent of ## - Each normal or test machine gets a NixOS configuration.
## the corresponding resource, NixOS configuration, and VM options, rather ## - Each normal or test machine gets a VM options entry.
## than the contrary. ## - Each normal machine gets a deployment.
nixops4Deployments = makeDeployments (addDefaultDeployment machines); ## - We add a “default” deployment with all normal machines.
flake.nixosConfigurations = makeConfigurations machines; ## - We add a “test” deployment with all test machines.
flake.vmOptions = makeVmOptions machines; nixops4Deployments = genAttrs machines makeDeployment' // {
default = makeDeployment machines;
test = makeDeployment testMachines;
};
flake.nixosConfigurations = genAttrs (machines ++ testMachines) makeConfiguration;
flake.vmOptions = genAttrs (machines ++ testMachines) makeVmOptions;
} }