From 4fda719992516d5624905207ff3140b30d600f43 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: Mon, 24 Feb 2025 12:52:19 +0100
Subject: [PATCH] Expose VM options in the flake

---
 infra/flake-part.nix | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/infra/flake-part.nix b/infra/flake-part.nix
index cf26e87c..81dba2ac 100644
--- a/infra/flake-part.nix
+++ b/infra/flake-part.nix
@@ -56,23 +56,40 @@ let
     };
   };
 
+  makeResourceConfig =
+    vmName:
+    (evalModules {
+      modules = [
+        nixops4ResourceNixosMockOptions
+        (makeResourceModule vmName)
+      ];
+    }).config;
+
   makeConfigurations = concatMapAttrs (
     _: vmNames:
     genAttrs vmNames (
       vmName:
       inputs.nixpkgs.lib.nixosSystem {
         modules = [
-          (evalModules {
-            modules = [
-              nixops4ResourceNixosMockOptions
-              (makeResourceModule vmName)
-            ];
-          }).config.nixos.module
+          (makeResourceConfig vmName).nixos.module
         ];
       }
     )
   );
 
+  makeVmOptions = concatMapAttrs (
+    _: vmNames:
+    genAttrs vmNames (vmName: {
+      inherit ((makeResourceConfig vmName).fediversityVm)
+        proxmox
+        vmId
+        sockets
+        cores
+        memory
+        ;
+    })
+  );
+
   machines = {
     git = [
       "vm02116"
@@ -94,6 +111,10 @@ 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;
 }