Merging the scheduled flake.lock pull request queues a host switch. The job only writes the merge SHA; the host re-checks that main is a lockfile-only bot bump before nixos-rebuild switch, so a runner restart cannot roll the deploy back.
5.8 KiB
Agent Instructions — hetzner-cloud-1
NixOS config for the Hetzner VPS: Forgejo at https://git.zoppelt.net and Murmur at mumble://git.zoppelt.net.
What This Repo Is
flake.nix— NixOS system flake (nixosConfigurations.hetzner-cloud-1)hosts/hetzner-cloud-1/— host-specific config (disk layout, hostname, SSH keys)modules/— reusable modules (forgejo.nix,murmur.nix,common.nix)secrets/— agenix secrets (secrets.nix+*.age); never commit plaintextcustom/— theme assets (TokyoNight CSS, logo, favicon)assets/— user avatar (avatar.jpeg)docker-compose/— legacy local Docker Compose reference
What This Repo Is Not
- Do not build Forgejo from source
- Do not version-control Forgejo data (
/var/lib/forgejo/lives on the host)
Deploy
Fresh install (wipes target disk)
nix run github:nix-community/nixos-anywhere -- \
--flake .#hetzner-cloud-1 \
--target-host root@git.zoppelt.net
Update existing deployment
nix run .#deploy
deploy.nodes sets host and SSH port 2222. apps.deploy passes --remote-build when the host arch ≠ target. Magic rollback is on by default. Use nixos-anywhere only for cold installs.
Auto-deploy of flake.lock bumps
.forgejo/workflows/update-flake-lock.yml opens chore/update-flake-lock. Merging that PR queues a deploy; other merges do not. The job only writes the merge SHA to /run/deploy-flake/request. deploy-flake-update.service then fetches main from the local bare repo and switches, detached from the runner, so a runner restart cannot trip deploy-rs magic rollback.
The host refuses the switch unless origin/main is that SHA, the diff is only flake.lock, and the commit is the bot bump (Deploy-On-Merge: flake-lock, or a merge of that branch). Any other workflow on this runner can mount the trigger directory; it cannot choose what gets deployed.
This path does not exist until the config that adds it has been deployed once with nix run .#deploy. A failed switch leaves /var/lib/deploy-flake/pending; systemctl start deploy-flake-update retries it.
Configuration
Forgejo settings are in modules/forgejo.nix. Murmur (Mumble) is in modules/murmur.nix.
Easily configurable values (top of the let block)
adminUser = "mz"; # initial admin username
adminEmail = "markus@zoppelt.net"; # admin email
avatarSrc = ../assets/avatar.jpeg; # path to avatar image
runnerName = "local"; # actions runner instance name
Other settings
- Forgejo auto-generates
app.iniand secrets in/var/lib/forgejo/custom/conf/— do not touch - Custom theme files are symlinked via
systemd.tmpfiles.rules - Admin user is created automatically on first start; password is written to
/var/lib/forgejo/.admin-password - Actions runner registration token is generated once (after Forgejo is up) at
/var/lib/forgejo/runner_token - Local runner service:
gitea-runner-local.service(package:forgejo-runner, jobs via Docker) - Runner instance URL is
https://git.zoppelt.net(not127.0.0.1) so job containers cangit clone - Runner labels:
nix(nixos/niximage),ubuntu-latest(Node/Debian fallback) - Prefer
runs-on: ubuntu-latestfor workflows that use JS actions (checkout,upload-artifact) - Workflows live in
.forgejo/workflows/; enable Actions per-repo if needed - Murmur listens on TCP+UDP
64738, hostnamegit.zoppelt.net(same ACME cert as nginx) - Murmur join password:
secrets/murmur-password.age→/run/agenix/murmur-password(MURMURD_PASSWORD=...) - Murmur SuperUser password:
secrets/murmur-superuser-password.age→/run/agenix/murmur-superuser-password(raw password only) - Recipients are in
secrets/secrets.nix(1Password SSH key + hostssh_host_ed25519_key; host key is required for decrypt-on-boot) - Creating or replacing a secret is encrypt-only (no private key). From
secrets/:printf 'MURMURD_PASSWORD=...\n' | nix run github:ryantm/agenix -- -e murmur-password.ageprintf '...\n' | nix run github:ryantm/agenix -- -e murmur-superuser-password.ageIf the.agefile already exists, remove it first —agenix -eon an existing file tries to decrypt. - Channel tree lives in
/var/lib/murmur/murmur.sqliteand survives deploys. SuperUser login in the Mumble client to add rooms. - No plaintext secrets in this repo
Troubleshooting
- 502 Bad Gateway:
systemctl status forgejo.service— usually means Forgejo failed to start. Checkjournalctl -u forgejo.service - Can't SSH after deploy: System SSH is on port 2222. Use Hetzner VNC console for recovery
- Runner not registering:
journalctl -u gitea-runner-local.service. To force re-register: stop the runner, delete/var/lib/forgejo/runner_tokenand/var/lib/gitea-runner/local/.runner, restartforgejothengitea-runner-local - Actions checkout fails / empty repo: job container was using
127.0.0.1:3000(itself). Runner URL must be the publicROOT_URL. After changing URL, ensure.runnerwas recreated (gitea-runner-localpreStart stamps.instance-url) - Actions jobs stuck: ensure Docker is up (
systemctl status docker) and the repo has Actions enabled - Flake bump merged but not deployed:
systemctl status deploy-flake-updateandjournalctl -u deploy-flake-update. The Actions job only queues the switch. If it failed after validation,systemctl start deploy-flake-updateretries/var/lib/deploy-flake/pending
Upstream workaround
The NixOS Forgejo module marks app.ini read-only after generation. On first start, forgejo migrate needs to write secrets back into it and crashes with "permission denied". modules/forgejo.nix overrides preStart to keep app.ini writable. Remove the override when upstream fixes this.