From b42d654ab69013699a24c1e2a7577af5486612ec 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: Tue, 25 Feb 2025 10:46:28 +0100
Subject: [PATCH 1/6] Track machines' descriptions

---
 infra/common/options.nix           | 9 +++++++++
 infra/flake-part.nix               | 3 +++
 infra/machines/fedi200/default.nix | 2 ++
 infra/machines/fedi201/default.nix | 4 ++++
 infra/machines/vm02116/default.nix | 3 +++
 infra/machines/vm02187/default.nix | 3 +++
 infra/proxmox-provision.sh         | 2 ++
 7 files changed, 26 insertions(+)

diff --git a/infra/common/options.nix b/infra/common/options.nix
index c8ec4aac..0e9d5b54 100644
--- a/infra/common/options.nix
+++ b/infra/common/options.nix
@@ -41,6 +41,15 @@ in
       '';
     };
 
+    description = mkOption {
+      description = ''
+        A human-readable description of the machine's purpose. It should be
+        constituted of a first line giving a very short description, followed
+        by a blank line, then followed by more details if necessary.
+      '';
+      default = "";
+    };
+
     ##########################################################################
     ## Virtualised hardware
 
diff --git a/infra/flake-part.nix b/infra/flake-part.nix
index 2088f390..a14a4539 100644
--- a/infra/flake-part.nix
+++ b/infra/flake-part.nix
@@ -115,9 +115,12 @@ let
     inherit ((makeResourceConfig { inherit vmName isTestVm; }).fediversityVm)
       proxmox
       vmId
+      description
+
       sockets
       cores
       memory
+
       hostPublicKey
       unsafeHostPrivateKey
       ;
diff --git a/infra/machines/fedi200/default.nix b/infra/machines/fedi200/default.nix
index db9950ea..bdea3217 100644
--- a/infra/machines/fedi200/default.nix
+++ b/infra/machines/fedi200/default.nix
@@ -2,6 +2,8 @@
   fediversityVm = {
     vmId = 200;
     proxmox = "fediversity";
+    description = "Testing machine for Hans";
+
     domain = "abundos.eu";
     ipv4 = {
       address = "95.215.187.200";
diff --git a/infra/machines/fedi201/default.nix b/infra/machines/fedi201/default.nix
index c0d1bd90..c8567117 100644
--- a/infra/machines/fedi201/default.nix
+++ b/infra/machines/fedi201/default.nix
@@ -1,5 +1,9 @@
 {
   fediversityVm = {
+    vmId = 201;
+    proxmox = "fediversity";
+    description = "FediPanel";
+
     domain = "abundos.eu";
     ipv4 = {
       address = "95.215.187.201";
diff --git a/infra/machines/vm02116/default.nix b/infra/machines/vm02116/default.nix
index 496b9854..cfee5639 100644
--- a/infra/machines/vm02116/default.nix
+++ b/infra/machines/vm02116/default.nix
@@ -1,5 +1,8 @@
 {
   fediversityVm = {
+    proxmox = "procolix";
+    description = "Forgejo";
+
     ipv4.address = "185.206.232.34";
     ipv6.address = "2a00:51c0:12:1201::20";
   };
diff --git a/infra/machines/vm02187/default.nix b/infra/machines/vm02187/default.nix
index 7310e9c1..82a1adef 100644
--- a/infra/machines/vm02187/default.nix
+++ b/infra/machines/vm02187/default.nix
@@ -1,5 +1,8 @@
 {
   fediversityVm = {
+    proxmox = "procolix";
+    description = "Wiki";
+
     ipv4.address = "185.206.232.187";
     ipv6.address = "2a00:51c0:12:1201::187";
   };
diff --git a/infra/proxmox-provision.sh b/infra/proxmox-provision.sh
index 3b5b7730..0ecaaa06 100755
--- a/infra/proxmox-provision.sh
+++ b/infra/proxmox-provision.sh
@@ -181,6 +181,7 @@ grab_vm_options () {
 
   proxmox=$(echo "$options" | jq -r .proxmox)
   vm_id=$(echo "$options" | jq -r .vmId)
+  description=$(echo "$options" | jq -r .description)
 
   if [ "$proxmox" != fediversity ]; then
     die "I do not know how to provision things that are not Fediversity VMs,
@@ -286,6 +287,7 @@ create_vm () {
     vmid=="$vm_id" \
     name=="$vm_name" \
     pool==Fediversity \
+    description=="$description" \
     \
     ide2=="local:iso/installer-$vm_name.iso,media=cdrom" \
     ostype==l26 \

From 8ba000307fb01564258e1af7924f6d450e4c1e00 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: Tue, 25 Feb 2025 11:27:52 +0100
Subject: [PATCH 2/6] Generate list of machines from config

---
 infra/README.md                    | 16 ++----------
 infra/machines.md                  | 15 +++++++++++
 infra/machines.md.sh               | 42 ++++++++++++++++++++++++++++++
 infra/machines/vm02116/default.nix |  1 +
 infra/machines/vm02187/default.nix |  1 +
 5 files changed, 61 insertions(+), 14 deletions(-)
 create mode 100644 infra/machines.md
 create mode 100644 infra/machines.md.sh

diff --git a/infra/README.md b/infra/README.md
index 0afde290..c43362f5 100644
--- a/infra/README.md
+++ b/infra/README.md
@@ -1,6 +1,7 @@
 # Infra
 
-This directory contains the definition of the VMs that host our infrastructure.
+This directory contains the definition of [the VMs](machines.md) that host our
+infrastructure.
 
 ## Provisioning VMs with an initial configuration
 
@@ -91,16 +92,3 @@ nixops4 apply
 ## Removing an existing VM
 
 See `infra/proxmox-remove.sh --help`.
-
-## Machines
-
-These machines are hosted on the Procolix Proxmox instance,
-to which non-Procolix members of the project do not have access.
-They host our stable infrastructure.
-
-  Machine   Proxmox       Description
-  --------- ------------- ------------------------
-  vm02116   Procolix      Forgejo
-  vm02187   Procolix      Wiki
-  fedi200   Fediversity   Testing machine for Hans
-  fedi201   Fediversity   FediPanel
diff --git a/infra/machines.md b/infra/machines.md
new file mode 100644
index 00000000..e2c49c0c
--- /dev/null
+++ b/infra/machines.md
@@ -0,0 +1,15 @@
+<!-- This file is auto-generated by `machines.md.sh` from the machines'
+     configuration. -->
+
+# Machines
+
+Currently, this repository keeps track of the following VMs:
+
+Machine | Proxmox | Description
+--------|---------|-------------
+[`fedi200`](./fedi200) | fediversity | Testing machine for Hans
+[`fedi201`](./fedi201) | fediversity | FediPanel
+[`vm02116`](./vm02116) | procolix | Forgejo
+[`vm02187`](./vm02187) | procolix | Wiki
+
+This table excludes all machines with names starting with `test`.
diff --git a/infra/machines.md.sh b/infra/machines.md.sh
new file mode 100644
index 00000000..4a2a5ca1
--- /dev/null
+++ b/infra/machines.md.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env sh
+set -euC
+
+cd "$(dirname "$0")"
+
+{
+cat <<\EOF
+<!-- This file is auto-generated by `machines.md.sh` from the machines'
+     configuration. -->
+
+# Machines
+
+Currently, this repository keeps track of the following VMs:
+
+Machine | Proxmox | Description
+--------|---------|-------------
+EOF
+
+vmOptions=$(
+  cd ..
+  nix eval \
+    --impure --raw --expr "
+      builtins.toJSON (builtins.getFlake (builtins.toString ./.)).vmOptions
+    " \
+    --log-format raw --quiet
+)
+
+## NOTE: `jq`'s `keys` is alphabetically sorted, just what we want here.
+for machine in $(echo "$vmOptions" | jq -r 'keys[]'); do
+  if [ "${machine#test}" = "$machine" ]; then
+    proxmox=$(echo "$vmOptions" | jq -r ".$machine.proxmox")
+    description=$(echo "$vmOptions" | jq -r ".$machine.description" | head -n 1)
+
+    printf '[`%s`](./%s) | %s | %s\n' "$machine" "$machine" "$proxmox" "$description"
+  fi
+done
+
+cat <<\EOF
+
+This table excludes all machines with names starting with `test`.
+EOF
+} >| machines.md
diff --git a/infra/machines/vm02116/default.nix b/infra/machines/vm02116/default.nix
index cfee5639..be461038 100644
--- a/infra/machines/vm02116/default.nix
+++ b/infra/machines/vm02116/default.nix
@@ -1,5 +1,6 @@
 {
   fediversityVm = {
+    vmId = 2116;
     proxmox = "procolix";
     description = "Forgejo";
 
diff --git a/infra/machines/vm02187/default.nix b/infra/machines/vm02187/default.nix
index 82a1adef..b389efb2 100644
--- a/infra/machines/vm02187/default.nix
+++ b/infra/machines/vm02187/default.nix
@@ -1,5 +1,6 @@
 {
   fediversityVm = {
+    vmId = 2187;
     proxmox = "procolix";
     description = "Wiki";
 

From 34476bf93b9f6be1504b7a2ffb30bd54aa8cae47 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: Tue, 25 Feb 2025 16:04:50 +0100
Subject: [PATCH 3/6] Add `jq` to the environment

---
 flake.nix | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flake.nix b/flake.nix
index 7338d405..96e4f815 100644
--- a/flake.nix
+++ b/flake.nix
@@ -60,6 +60,7 @@
               inputs'.agenix.packages.default
               inputs'.nixops4.packages.default
               pkgs.httpie
+              pkgs.jq
             ];
             shellHook = config.pre-commit.installationScript;
           };

From 816099eb1f8873578ee79d84eded4020d7396b31 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: Thu, 27 Feb 2025 12:05:01 +0100
Subject: [PATCH 4/6] Document regenerating the list of machines

---
 infra/README.md | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/infra/README.md b/infra/README.md
index c43362f5..133f6a32 100644
--- a/infra/README.md
+++ b/infra/README.md
@@ -30,7 +30,7 @@ everything will become much cleaner.
 
 3. Run the provisioning script:
    ```
-   sh infra/proxmox-provision.sh 117
+   sh infra/proxmox-provision.sh fedi117
    ```
    The script can take several ids at the same time. It requires some
    authentication options and provides several more. See `--help`.
@@ -46,7 +46,11 @@ everything will become much cleaner.
 
    FIXME: Make the provisioning script do that for us.
 
-7. Commit the machine's configuration, public key, etc.
+7. Regenerate the list of machines:
+   ```
+   sh infra/machines.md.sh
+   ```
+   Commit it with the machine's configuration, public key, etc.
 
 8. At this point, the machine contains a very basic configuration that contains
    just enough for it to boot and be reachable. Go on to the next section to

From 52e4dc8aeca257e04f66256a0d952f27df488575 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: Thu, 27 Feb 2025 12:14:22 +0100
Subject: [PATCH 5/6] Make ShellCheck happy

---
 infra/machines.md.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/infra/machines.md.sh b/infra/machines.md.sh
index 4a2a5ca1..ea1b0208 100644
--- a/infra/machines.md.sh
+++ b/infra/machines.md.sh
@@ -31,6 +31,7 @@ for machine in $(echo "$vmOptions" | jq -r 'keys[]'); do
     proxmox=$(echo "$vmOptions" | jq -r ".$machine.proxmox")
     description=$(echo "$vmOptions" | jq -r ".$machine.description" | head -n 1)
 
+    # shellcheck disable=SC2016
     printf '[`%s`](./%s) | %s | %s\n' "$machine" "$machine" "$proxmox" "$description"
   fi
 done

From 0b18938eaa4136bdab2677d2f4134cad7e567d6a 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: Thu, 27 Feb 2025 12:22:27 +0100
Subject: [PATCH 6/6] Support specifying disk size

---
 infra/common/options.nix   | 6 ++++++
 infra/flake-part.nix       | 1 +
 infra/proxmox-provision.sh | 7 ++++---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/infra/common/options.nix b/infra/common/options.nix
index 0e9d5b54..230eea5d 100644
--- a/infra/common/options.nix
+++ b/infra/common/options.nix
@@ -71,6 +71,12 @@ in
       default = 2048;
     };
 
+    diskSize = mkOption {
+      type = types.int;
+      description = "The amount of disk of the VM in GiB.";
+      default = 32;
+    };
+
     ##########################################################################
     ## Networking
 
diff --git a/infra/flake-part.nix b/infra/flake-part.nix
index a14a4539..08be9cfe 100644
--- a/infra/flake-part.nix
+++ b/infra/flake-part.nix
@@ -120,6 +120,7 @@ let
       sockets
       cores
       memory
+      diskSize
 
       hostPublicKey
       unsafeHostPrivateKey
diff --git a/infra/proxmox-provision.sh b/infra/proxmox-provision.sh
index 0ecaaa06..8b4d4b55 100755
--- a/infra/proxmox-provision.sh
+++ b/infra/proxmox-provision.sh
@@ -191,6 +191,7 @@ but I got proxmox = '%s' for VM %s." "$proxmox" "$vm_name"
   sockets=$(echo "$options" | jq -r .sockets)
   cores=$(echo "$options" | jq -r .cores)
   memory=$(echo "$options" | jq -r .memory)
+  disk_size=$(echo "$options" | jq -r .diskSize)
 
   host_public_key=$(echo "$options" | jq -r .hostPublicKey)
   host_private_key=$(echo "$options" | jq -r .unsafeHostPrivateKey)
@@ -199,8 +200,8 @@ but I got proxmox = '%s' for VM %s." "$proxmox" "$vm_name"
     die 'I do not know what to do with a private key but no public key.'
   fi
 
-  printf 'done grabing VM options for VM %s. Got:\n  id: %d\n  sockets: %d\n  cores: %d\n  memory: %d MiB\n' \
-    "$vm_name" "$vm_id" "$sockets" "$cores" "$memory"
+  printf 'done grabing VM options for VM %s. Got:\n  id: %d\n  sockets: %d\n  cores: %d\n  memory: %d MiB\n  disk size: %d GiB\n' \
+    "$vm_name" "$vm_id" "$sockets" "$cores" "$memory" "$disk_size"
 }
 
 ################################################################################
@@ -297,7 +298,7 @@ create_vm () {
     agent==1 \
     \
     scsihw==virtio-scsi-single \
-    scsi0=='linstor_storage:32,discard=on,ssd=on,iothread=on' \
+    scsi0=="linstor_storage:$disk_size,discard=on,ssd=on,iothread=on" \
     \
     sockets=="$sockets" \
     cores=="$cores" \