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; }; diff --git a/infra/README.md b/infra/README.md index 0afde290..133f6a32 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 @@ -29,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`. @@ -45,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 @@ -91,16 +96,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/common/options.nix b/infra/common/options.nix index c8ec4aac..230eea5d 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 @@ -62,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 2088f390..08be9cfe 100644 --- a/infra/flake-part.nix +++ b/infra/flake-part.nix @@ -115,9 +115,13 @@ let inherit ((makeResourceConfig { inherit vmName isTestVm; }).fediversityVm) proxmox vmId + description + sockets cores memory + diskSize + hostPublicKey unsafeHostPrivateKey ; 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..ea1b0208 --- /dev/null +++ b/infra/machines.md.sh @@ -0,0 +1,43 @@ +#!/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) + + # shellcheck disable=SC2016 + 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/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 529a52b7..2f8978d7 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..be461038 100644 --- a/infra/machines/vm02116/default.nix +++ b/infra/machines/vm02116/default.nix @@ -1,5 +1,9 @@ { fediversityVm = { + vmId = 2116; + 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..b389efb2 100644 --- a/infra/machines/vm02187/default.nix +++ b/infra/machines/vm02187/default.nix @@ -1,5 +1,9 @@ { fediversityVm = { + vmId = 2187; + 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..8b4d4b55 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, @@ -190,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) @@ -198,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" } ################################################################################ @@ -286,6 +288,7 @@ create_vm () { vmid=="$vm_id" \ name=="$vm_name" \ pool==Fediversity \ + description=="$description" \ \ ide2=="local:iso/installer-$vm_name.iso,media=cdrom" \ ostype==l26 \ @@ -295,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" \