1
0
Fork 0

Merge pull request 'Generate machines' list automatically' () from Niols/Fediversity:generate-machines-list-by-hand into main

Reviewed-on: 
Reviewed-by: kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
kiara Grouwstra 2025-02-27 22:06:57 +01:00
commit 6e386a9fd6
11 changed files with 106 additions and 19 deletions

View file

@ -60,6 +60,7 @@
inputs'.agenix.packages.default
inputs'.nixops4.packages.default
pkgs.httpie
pkgs.jq
];
shellHook = config.pre-commit.installationScript;
};

View file

@ -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

View file

@ -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

View file

@ -115,9 +115,13 @@ let
inherit ((makeResourceConfig { inherit vmName isTestVm; }).fediversityVm)
proxmox
vmId
description
sockets
cores
memory
diskSize
hostPublicKey
unsafeHostPrivateKey
;

15
infra/machines.md Normal file
View file

@ -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`.

43
infra/machines.md.sh Normal file
View file

@ -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

View file

@ -2,6 +2,8 @@
fediversityVm = {
vmId = 200;
proxmox = "fediversity";
description = "Testing machine for Hans";
domain = "abundos.eu";
ipv4 = {
address = "95.215.187.200";

View file

@ -1,5 +1,9 @@
{
fediversityVm = {
vmId = 201;
proxmox = "fediversity";
description = "FediPanel";
domain = "abundos.eu";
ipv4 = {
address = "95.215.187.201";

View file

@ -1,5 +1,9 @@
{
fediversityVm = {
vmId = 2116;
proxmox = "procolix";
description = "Forgejo";
ipv4.address = "185.206.232.34";
ipv6.address = "2a00:51c0:12:1201::20";
};

View file

@ -1,5 +1,9 @@
{
fediversityVm = {
vmId = 2187;
proxmox = "procolix";
description = "Wiki";
ipv4.address = "185.206.232.187";
ipv6.address = "2a00:51c0:12:1201::187";
};

View file

@ -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" \