Skip to content
scorsiPublic

About

設計図 — my homelab blueprint: nix-darwin and NixOS hosts, services, networking and secrets in one Nix flake (mirror of my Forgejo)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

sekkeizu (設計図)

Personal Nix flake for all my machines, built with flake-parts and the dendritic pattern: every feature lives in its own file under modules/, and contributes to as many of darwin / nixos / homeManager as it needs.

The generic part (options kiso.*, shell, git, ssh, tmux, Nix itself, home-manager wiring, the flake plumbing) is kiso, a public flake-parts module imported in flake.nix: hosts use its features by name like their own (darwin.fish, homeManager.git…). This repo keeps the machines, the services, the network, the secrets and the values; what must not be public (where the services live, public keys) sits in modules-private/, encrypted in the repository with git-crypt (see Encrypted trees).

Hosts

Host Machine OS
jiban Mac Mini M4 macOS (nix-darwin)
ishizue NixOS VM on jiban (vfkit) NixOS
torii-cdg Vultr instance, Paris NixOS
hashira-01, hashira-02 Lenovo ThinkCentre M75q, home LAN NixOS
shosai Dell Latitude 7440 NixOS

Layout

modules/
  meta/    the values of kiso's options (owner.nix), this repo's options (services, expiring secrets)
  home/    home-manager features of this repo (ssh-hosts, gh, Claude Code); the generic ones are kiso's
  macos/   nix-darwin-only features (headless server, auto-login, VM host, linux builder, reminders)
  nixos/   NixOS-only features (server, Forgejo, rirekisho)
  backup/  azukari: the object store on hashira-01 and each node's backup exports
  cache/   oroshi: the Nix binary cache on hashira-01, its readers and jiban's uploader
  network/ kekkai, annai, hanko, genkan
  desktop/ the Sway session of a workstation (SwayFX, Stylix, Plymouth, LibreWolf, everyday apps)
  vm/      NixOS guest base for VMs on a Mac (vfkit, EFI)
  flake/   this repo's apps (rekey-host, set-autologin-password); the rest of the plumbing is kiso's
  hosts/   one file per machine: its identity + the features it imports
modules-private/  git-crypt, laid out like modules/: where services live (meta/endpoints.nix), public keys (meta/keys.nix)
secrets/   sops files per host, git-crypt on top
infra/     OpenTofu: cloud resources and public DNS (see Infrastructure)
scripts/
  bootstrap.sh   turns a fresh Mac into a working jiban
  hooks/         pre-commit: refuses an encrypted tree committed in clear

A feature file declares flake.modules.<class>.<name>; a host file just lists the names it wants. Adding a feature never requires touching an existing file.

Usage

nix run .#switch   # rebuild + diff against the current generation (sudo prompt included)
nix run .#check     # nix flake check
nix run .#fmt       # nix fmt (nixfmt-tree)
nix run .#rekey-host -- <host> --public-key <verified-key.pub>  # new host key: update its recipient, including shared secrets
nix run .#install-ishizue    # on jiban: build ishizue's disk image and start it (once)
nix run .#deploy-ishizue     # over kekkai: build inside the VM, then switch in a detached unit (also deploy-torii-cdg, deploy-hashira-01, deploy-hashira-02: built on the host)
nix develop          # shell with nixfmt, statix, deadnix, shellcheck, just, nvd

Reinstalling a Mac from scratch

Steps in execution order. Everything not listed here is declarative and comes back with the switch. The repo is private (SSH over FIDO2 key), so the bootstrap script cannot be fetched with curl from GitHub: bring scripts/bootstrap.sh and scripts/bootstrap.nim over, side by side (AirDrop, scp, USB stick).

  1. Before wiping: everything pushed (sekkeizu and ~/repositories/kanna), and the password manager holds the two FIDO2 identities of ~/.config/sops/age/keys.txt and the admin age key.
  2. Erase All Content and Settings, then in Setup Assistant: create the account with the name set in modules/meta/owner.nix, and turn FileVault off when the assistant offers it (with FileVault on, macOS ignores /etc/kcpassword and the headless boot stops at the unlock screen).
  3. Bootstrap, with the first FIDO2 key plugged in:
    bash bootstrap.sh --repo git@github.com:scorsi/sekkeizu.git
    It installs Nix, then compiles and runs bootstrap.nim (Nim and clang from nixpkgs), which installs the Command Line Tools, pulls the key handle (ssh-keygen -K: PIN, then touch), clones sekkeizu and kanna (~/repositories/kanna, the live Neovim config), fetches the flake inputs from their GitHub mirrors (Forgejo isn't reachable yet) and runs the first switch. Until kekkai is up (second switch, step 8), run Nix commands through nu scripts/via-github.nu …. That switch can complain that sops cannot decrypt kcpassword: expected, the host key is new (step 7 fixes it).
  4. One ssh-keygen -K per additional key: plug the next FIDO2 key, then cd ~/.ssh && ssh-keygen -K (the bootstrap only handled the first one).
  5. Screen Sharing: System Settings → General → Sharing → Screen Sharing on (not declarative). Remote Login (sshd) is declared.
  6. sops identities: put the two AGE-PLUGIN-FIDO2-HMAC-1… lines from the password manager into ~/.config/sops/age/keys.txt (on the machine where step 7 runs; jiban itself is fine). Each decryption then takes a touch of either key; the admin key stays in the password manager (break-glass, see .sops.yaml).
  7. Re-key: the reinstall generated a new SSH host key, so the old age recipient is dead. On jiban, nix run .#rekey-host -- jiban reads the local public host key. From another machine, pass --public-key <verified-key.pub> using a key copied from jiban's console or another independently verified source. Review and commit .sops.yaml and every changed file under secrets/, including shared secrets (pull them on jiban if it ran elsewhere).
  8. Second switch: nix run .#switch (or drs): the secrets now decrypt and /etc/kcpassword is installed.
  9. Immediate screen lock: sysadminctl -screenLock immediate -password - (type the account password when prompted). The askForPassword default alone is not honoured by recent macOS, and the command needs the password, so it cannot be declared. Check with sysadminctl -screenLock status.
  10. Reboot and check: auto-login works, the screen is locked (password asked), and ssh jiban still answers.

ishizue (NixOS VM on jiban)

A classic NixOS machine (own disk, own /nix/store, systemd-boot) booted in EFI mode by vfkit (Virtualization.framework). A LaunchAgent of the owner's session (org.nixos.vm-ishizue) starts it at login, i.e. at boot thanks to auto-login. vCPU, RAM, disk size and MAC are declared on the Mac side: sekkeizu.vms.ishizue in modules/hosts/jiban.nix. Reachable over kekkai (ishizue.kekkai.uchi.<domain>, used by deploys) and as ishizue.local from jiban (NAT bridge, the deploy fallback).

The bridge address in sekkeizu.bridgeAddresses is reserved for the VM's MAC in /etc/bootptab, managed by vfkit-host. A fixed MAC alone does not reserve a DHCP address. After first installing or changing this reservation, reboot jiban before relying on it: this reloads bootpd and makes the guest obtain a new lease. Do not delete live DHCP leases or assign the address manually inside the guest. Check /etc/bootptab and, over ssh ishizue.local, ip -4 address against bridgeAddresses before checking annai, kekkai and the observability stores, whose listeners, firewall rules and clients all use that address. An existing lease held by another VM must be resolved before starting the reserved VM.

State, in ~/.local/state/vm/ishizue/:

  • disk.raw: the disk (sparse; the guest's weekly fstrim gives freed blocks back to the Mac).
  • efi-vars: the EFI variable store (boot order, systemd-boot one-shot entries). Keep it with the disk; without it the VM still boots (fallback EFI/BOOT/BOOTAA64.EFI) but loses those.
  • console.log (guest console) and vfkit.log, rotated at each start (3 previous kept as .1-.3): vfkit never reopens them, so newsyslog couldn't rotate them while the VM runs.

Ephemeral root

/ is a 1 GB tmpfs, rebuilt empty at every boot. The disk (ext4, label nixos) is mounted on /persist and carries /nix (bind of /persist/nix) and everything declared to survive. Each feature adds its own state to sekkeizu.persist.directories / .files (the kajiba runner keeps its source cache…); modules/nixos/impermanence.nix aggregates them (via preservation) and keeps the machine-id, the uid/gid map, /var/lib/systemd, /var/log and the owner's whole home. The SSH host key lives directly at /persist/etc/ssh/ssh_host_ed25519_key (sops decrypts before the bind mounts exist).

Anything installed by hand outside the declared paths is gone at the next reboot: declare it.

Day to day:

  • Deploy: nix run .#deploy-ishizue (nixos-rebuild build inside the VM; the profile and switch-to-configuration then run in a transient sekkeizu-switch-<time> unit, so a dropped session cannot interrupt them: the app follows its journal, reconnects for up to 3 min and exits with its status). Connects as root@ over kekkai (key-only, FIDO2 keys, allowed only from the Mac's NAT bridge and kekkai), one shared SSH connection: one touch per deploy. When kekkai or annai is broken: DEPLOY_HOST=root@ishizue.local nix run .#deploy-ishizue (the bridge; DEPLOY_HOST=root@torii-cdg.scorsi.dev for torii-cdg, its public SSH). Interactive sudo in the VM still uses pam_rssh (a touch each).
  • Rollback: nix run .#deploy-ishizue -- --rollback, or for one boot only, sudo bootctl set-oneshot nixos-generation-<n>.conf in the VM, then reboot.
  • Restart: launchctl kickstart -k gui/$(id -u)/org.nixos.vm-ishizue. A clean poweroff of the guest stays stopped; start it again with launchctl kickstart gui/$(id -u)/org.nixos.vm-ishizue.
  • Resources: edit sekkeizu.vms.ishizue, switch jiban, restart the VM. A bigger diskSize only applies to a new install.

Installing it (first time, or --force to start over with an empty disk)

  1. Linux builder: uncomment darwin.linux-builder in modules/hosts/jiban.nix, nix run .#switch.
  2. Install: nix run .#install-ishizue builds the disk image (~4 min), copies it sparse, grows it to diskSize, writes ishizue's identity into it and starts the VM. It refuses to overwrite an existing disk without -- --force. The builder's disk is 40 GB (sparse, recreated at each start).
  3. First boot (~15 s): the partition grows. The identity comes from secrets/ishizue/identity.yaml (sops, admin key: SSH host key), written into /persist offline with debugfs before the first boot: same host key (known_hosts, .sops.yaml unchanged, the secrets decrypt at once). Nothing else to do; go to 6.
  4. Without identity.yaml (a genuinely new machine): a new SSH host key is generated. Obtain /etc/ssh/ssh_host_ed25519_key.pub through the VM's trusted console and save it as ishizue-host-key.pub. Verify its fingerprint (ssh-keygen -lf ishizue-host-key.pub) before replacing the old known_hosts entries (ssh-keygen -R ishizue.local; ssh-keygen -R ishizue). Check the fingerprint when connecting with ssh ishizue.local.
  5. Re-key (only after 4): nix run .#rekey-host -- ishizue --public-key ishizue-host-key.pub. Review and commit .sops.yaml and all changed secrets, including secrets/hanko/. The command updates tracked files selected by SOPS rules and restores their original ciphertext if an update fails. After an interrupted process, inspect git diff and rerun it to finish. To keep this new identity for the next reinstall, store it in secrets/ishizue/identity.yaml (ssh_host_ed25519_key, ssh_host_ed25519_key_pub: the files under /persist, piped straight into sops set --value-stdin).
  6. Deploy: nix run .#deploy-ishizue, built inside the VM.
  7. Drop the linux builder: comment darwin.linux-builder again, nix run .#switch (nix-darwin deletes its disk).

Forge and web

The web services are <service>.uchi.<domain> names, which only annai resolves (CNAME to genkan.uchi, which has both hashira's kekkai addresses): genkan on 443 on each of them, the same sites, each with the *.uchi wildcard of its own hanko, reached over kekkai (its allowInbound opens tcp/443 to jiban); the LAN keeps 443 closed. The nodes' hikyaku and azukari-backup pin genkan.uchi and azukari.uchi to both genkan addresses in /etc/hosts (the nodes resolve through Quad9) and reach genkan's services listener on 9443: SNI passthrough only, no web site, so kekkai opens it to torii-cdg's hikyaku without opening the web sites. Git over SSH uses the same Forgejo name: genkan's tcp passthrough on 2222 forwards it raw, with a PROXY v2 header, to Forgejo's own SSH server on ishizue over kekkai. A name served on one hashira only (résumé, Nix cache) reaches the other's 443 and is relayed raw by SNI, behind a PROXY v2 header, to the owner's relay listener on 7443 (kekkai opens it between the two hashira only, PROXY headers trusted from the other hashira's kekkai address only), so the owner logs the real client. genkan's TLS ports all end in 443, the prefix gives the role:

Port Listener Role
443 default the web sites, over kekkai
7443 relay the web sites, from the other hashira's genkan only, PROXY v2
8443 edge public names from torii-cdg's genkan, PROXY v2 (hashira-02 only)
9443 services machine-to-machine SNI passthrough, no web site
Service Address Behind
Forgejo https://forgejo.uchi.<domain> genkan → ishizue:3000 over kekkai
Git (SSH) ssh://git@forgejo.uchi.<domain>:2222 genkan passthrough → Forgejo's SSH server
Résumé https://rirekisho.uchi.<domain> genkan, static files (no publisher since the Forgejo runners were removed); hashira-01's genkan relays the name by SNI to hashira-02's relay (7443)
Nix cache https://oroshi.uchi.<domain>/nix hashira-01's genkan → oroshi on loopback; hashira-02's genkan relays the name by SNI to hashira-01's relay (7443)
Backups https://azukari.uchi.<domain>:9443 genkan passthrough by SNI → azukari-server (hashira-01:5000), mTLS end to end
Metrics, logs https://genkan.uchi.<domain>:9443, TLS name masu.internal / nisshi.internal genkan passthrough by SNI → masu / nisshi (hashira-01:9472, 9473), the nodes' hikyaku

Addresses are declared once, in modules-private/meta/endpoints.nix (sekkeizu.services.*); genkan's sites, annai's records and Forgejo's ROOT_URL read them from there.

Public exposure: only the résumé. Its public names (rirekisho.public in endpoints.nix: rirekisho.soto.<domain>, with rirekisho.<domain> and cv.scorsi.me as CNAMEs to it, records in modules-private/meta/public.nix) point at torii-cdg, where genkan v1.0 listens on tcp/443 and forwards them by SNI, TLS untouched, behind a PROXY v2 header, to hashira-02's edge listener (<hashira-02 kekkai IPv4>:8443, kekkai allowInbound from torii-cdg only, PROXY headers trusted from torii-cdg's kekkai address only), hashira-02 alone: a genkan tcp route has one backend. hashira-02 terminates TLS with hanko's rirekisho-public certificate. Only sites that name the edge listener are served there (genkan ADR 0013): Forgejo and every other *.uchi name answer 404 through a public SNI. tcp/80 on torii-cdg is genkan's redirect listener (v1.1): every request gets a 301 to https:// on the same host and path, answered on torii; port 80 never crosses kekkai. No git SSH on a public port.

  • Git over SSH on 2222: Forgejo's own SSH server, not the system sshd, which stays key-only for the owner. kekkai's allowInbound opens tcp/2222 to jiban. No shared git account on the system, no AllowUsers change; the server only speaks git, with the keys stored in Forgejo (owner.sshKeys, added by the forgejo-admin unit).
  • Backups: azukari (modules/backup/azukari.nix). Each export of a node has its own azukari-backup-<export> unit and timer (1 h random delay): daily, masu-days and nisshi-days at 01:00 UTC (after their stores seal the previous day at 00:10 UTC). A run first refreshes its export in /persist/backups/<export>, then sends it to the store on hashira-01 (bucket backup, DAS disk ZN1374ZM). Exports: forgejo-dump on ishizue (forgejo dump, one tar replaced each run), hanko-account on hashira-01 and hashira-02 (each one's ACME account key, account.key), masu-days and nisshi-days on hashira-01 (each store's closed days, hard-linked; the open day is never exported, so the last day lags until it closes). Retention runs dry (7-day keep, enabled = false). The store replicates the bucket every 6 h to two copies (azukari ADR 0008): offsite, the Storage Box's backup subaccount under azukari/ (rsync over SSH, key azukari-offsite-key in secrets/hashira-01/azukari-offsite.yaml, the box's host key pinned; the directory was made once with that key from hashira-01, the owner having no SSH access to the box), and local, the USB disk 53RFWOD0T (modules/nixos/replica-disk.nix, its own LUKS key, /mnt/replica/53RFWOD0T/azukari; a run is skipped while it is not mounted). Each copy is a restore source as it is. Each export is its own snapshot (azukari ADR 0030). Run one now: systemctl start azukari-backup-<export>; list: sudo -u azukari-backup azukari backup snapshots /etc/azukari/azukari-backup.toml <export>; restore with azukari backup restore <config> <export> <snapshot> <empty dir> (as root to restore owners), or restore --verify to read everything back without writing. Without the store (azukari ADR 0029), add --from-dir <copy>/backup (the USB replica, or the box's azukari/backup fetched with rsync): only the node's config and data key are needed. The former restic repository was deleted from the Storage Box (2026-10-30) once a restore from both copies was checked; the box's weekly snapshots (.zfs/) keep it for about 10 weeks, readable with restic-password and backup-pull-key from secrets/jiban/secrets.yaml: drop both once the last snapshot holding it has expired.
  • Observability retention: masu and nisshi keep 400 days of data, configured from modules/observability/retention-days.json. The masu-days and nisshi-days exports mirror what the store holds: a day the store drops leaves the export too, and stays in earlier azukari snapshots.
  • Hanko account recovery: the hanko-account export holds the current ACME account key; hanko never replaces it by itself (hanko ADR-0008), and earlier keys stay in earlier snapshots. On a replacement host, restore the key before enabling Hanko. On an existing host, first stop hanko-node.timer, hanko-node-renew.service and hanko-node.service. Select the key belonging to the account URI pinned in sekkeizu.acmeAccounts, then install it as /var/lib/hanko/account.key, owner and group hanko, mode 0600 (state directory hanko:hanko, mode 0751). Do not overwrite an existing key without comparing it and keeping its backup. Start hanko-node.timer only after restoring the identity; a new key would create a different account and fail the pinned CAA policy. Restore the key from a trusted backup, never by creating an ACME account as a recovery test. A missing key fails the export, hence the backup run, including at first boot before restoration. This also reports a lost identity on an existing host instead of silently skipping it.
  • CI: kajiba runners (modules/nixos/kajiba.nix, feature kajiba-runner) on hashira-01, hashira-02 and ishizue. On each, the runner and nix-daemon share ci.slice (OOM kill beyond), with per-host values in runnerHosts: 2 jobs × 4 cores in 9 GiB / 8 CPUs on the hashira, 1 job × 2 cores in 5 GiB / 2 CPUs (plus up to 2 GiB of swap) on ishizue. This also limits manual builds using that daemon. Finish existing builds before deploying a slice change, or reboot: a daemon restart alone can leave old build processes in their previous cgroup.
  • Résumé: repository rirekisho (Astro, its own flake), served by genkan from /var/lib/rirekisho, on the overlay and publicly through torii-cdg (above). Its Forgejo Actions workflow no longer has a runner: nothing publishes there until kajiba's CI does.

Manual steps, in order

  1. Certificate: hanko (modules/network/hanko.nix) issues *.uchi.<domain> before genkan needs it; until then genkan runs and fails the handshakes (certificate-not-ready).
  2. Deploy ishizue: nix run .#deploy-ishizue.
  3. Log in: user = owner.name, password: sops -d --extract '["forgejo-admin-password"]' secrets/ishizue/secrets.yaml (the forgejo-admin unit resets the account to that password at each Forgejo start).

Home of the repositories

The repositories live on Forgejo (origin) and are push-mirrored to GitHub (the fallback) at every commit. Which repositories exist, their settings and their mirrors are declared in koseki (OpenTofu): sekkeizu runs Forgejo, koseki says what is in it.

  • Inputs come from Forgejo: the scorsi-* inputs are git+ssh URLs on Forgejo (LAN, no dependence on GitHub). GitHub is the recovery path, for a fresh install or when Forgejo is down: nu scripts/via-github.nu <command> (e.g. nix run .#switch) rewrites the Forgejo URLs to the mirrors through git's environment; Nix still checks the revs and hashes of flake.lock (identical either way: checked). The bootstrap clones sekkeizu from GitHub and fetches the inputs that way by itself.

  • Owner keys: the forgejo-admin unit reconciles only the keys it manages (sekkeizu:owner: titles, or legacy keys adopted by exact title and content and recorded in Forgejo's state directory); a failed API request fails provisioning and is retried on the next run.

  • switch as root: kiso's switch fetches the inputs as the user (SSH agent, a touch) before sudo darwin-rebuild, which then finds them in the store.

  • Mirror token: kept in koseki; only its expiry date is declared here (modules/meta/github-mirror-token.nix, sekkeizu.expiringSecrets): jiban notifies daily and every switch warns from 30 days before.

  • Verified commits: each FIDO2 key must be verified once in Forgejo (Settings → SSH / GPG keys → Verify, then the ssh-keygen -Y sign command it shows, with that key plugged in). Forgejo only offers this through the web form; redo it for a new key or a reinstalled Forgejo.

Encrypted trees

secrets/ and modules-private/ are encrypted by git-crypt (.gitattributes): plain in an unlocked clone, ciphertext in the repository and on GitHub. Secrets stay sops files underneath: whatever Nix reads ends up in the world-readable store, so modules-private/ holds values only, never a secret.

  • Key: one symmetric key, in the password manager (base64) and in sops (secrets/<host>/git-crypt-key). From an unlocked clone: sops -d secrets/jiban/git-crypt-key | base64.
  • Unlock a clone: base64 -d > key, git-crypt unlock key, delete key, then git config core.hooksPath scripts/hooks (the bootstrap does all of it with --git-crypt-key).
  • The leak to avoid: in a clone that was never unlocked, git skips the filter and would commit a new file of these trees in clear. scripts/hooks/pre-commit refuses that commit.
  • A locked clone does not evaluate: the modules of modules-private/ are ciphertext.
  • sops keys (.sops.yaml): every file is encrypted to its host (activation, unattended), the two FIDO2 keys and the admin key. No private key on disk: keys.txt only holds the FIDO2 identities (age-plugin-fido2-hmac -g, touch only, separate identity; useless without the physical key), so any human decryption takes a touch. The admin key is the break-glass, kept only in the password manager. A new FIDO2 key: generate it, add its classic age1… recipient to .sops.yaml (the anchor names the serial number printed on the key), sops updatekeys every file. Recipient order is the touch count: sops tries them in order and the plugin needs a touch for each stanza it tries, its own or not. The daily key comes first in every rule and first in keys.txt, so one touch per decryption (updatekeys keeps a file's existing order). rekey-host changes recipients, not data keys. For a compromised host key, remove its recipient, run sops rotate on the affected current files and rotate the credentials themselves. Old Git ciphertext remains decryptable with the compromised key; re-encryption cannot revoke that history.

On macOS, the first switch without saved ciphertext fingerprints restarts hikyaku and kekkai-node once. A failed restart aborts activation and skips subsequent steps. Its fingerprint is not saved, so rerunning the switch retries it; successful earlier restarts are already recorded.

Infrastructure (OpenTofu)

What runs outside the house, in plain HCL under infra/. Each stack has its own state; modules are shared between stacks.

infra/
  encryption.tf     state and plan encryption, symlinked into every stack
  modules/
    vultr-node/     instance, firewall group (given ports and ICMP, v4 and v6), reserved IPv4
    dns-zone/       one Porkbun zone: records, optional null-mail (null MX, SPF -all, DMARC reject)
  stacks/
    torii/          Vultr, `torii-<region>`, region `cdg` (Paris) by default; ICMP, tcp/22, 53, 80, 443, udp/53, 4800-4802
    storage/        Hetzner Storage Box BX11 (fsn1), weekly snapshots, subaccount `backup`: azukari's replica
    dns/            scorsi.dev and scorsi.me at Porkbun: the delegation to annai soto (NS, glue); reads torii's addresses
  • Tooling: the infra shell (OpenTofu behind a tofu wrapper, sops, the FIDO2 age plugin, tofu-state-key), loaded by direnv under infra/ (direnv allow infra once), or nix develop .#infra. Run tofu from a stack directory.
  • Providers: exact versions in each stack, .terraform.lock.hcl committed with the hashes of darwin_arm64, linux_amd64 and linux_arm64. After a version bump: tofu providers lock -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64.
  • State: local terraform.tfstate, committed, encrypted by OpenTofu itself (AES-GCM, key from a passphrase through PBKDF2, enforced). Commit it after every apply. No locking: one operator.
  • Secrets: secrets/infra/tofu.yaml (sops, keys as in "Encrypted trees", no host key): decrypting takes a touch. Keys: vultr_api_key, porkbun_api_key, porkbun_secret_key, hcloud_token, state_passphrase, install_password (the NixOS ISO's nixos user while installing a Vultr host, see modules/nixos/vultr-guest.nix). The shell's tofu decrypts the file once per plan, apply, destroy, refresh, import or console (one touch) and passes the run the API keys the stack declares as ephemeral variables (TF_VAR_*, never in the state or the plan) and the state passphrase, which the external key provider tofu-state-key hands to OpenTofu (modules/flake/infra.nix). For that run they sit in the environment of tofu and its providers. A bare OpenTofu still works for the state (tofu-state-key then calls sops each time) but asks for the keys.
  • Order: storage and torii are independent; dns needs torii applied (its state holds the addresses).

Manual steps, in order

  1. Porkbun: Domain Management → API Access on for scorsi.dev and scorsi.me (per domain; without it the API answers API_ACCESS_DISABLED). API key limited to the DNS permission on those two domains. Delete the default parking records (ALIAS/CNAME to pixie.porkbun.com) if the domains have them.
  2. Vultr: API key, access restricted to your IP addresses (access control of the API settings).
  3. Hetzner: Console project → Security → API token, read and write.
  4. Secrets file: sops secrets/infra/tofu.yaml with the five keys (state_passphrase: openssl rand -base64 36).
  5. Apply, from each stack: tofu init, tofu plan, tofu apply; commit terraform.tfstate.
  6. DNSSEC and delegation: annai's soto zones are currently unsigned. Leave the domain's DNSSEC section at Porkbun empty: no DS record at the parent zone. Before delegating to annai, remove any DS from the previous DNS provider and wait for its TTL to expire, then change the nameservers (and glue records). A stale DS makes validating resolvers reject the unsigned zone. Publish a DS only after every authoritative server serves a signed zone and its DNSKEY has been verified; Porkbun's DNSSEC form publishes that DS, it does not sign annai's zones.
  7. restic's password: restic-password in secrets/jiban/secrets.yaml (already set; a new one means a new repository). jiban's and azukari-server's keys reach the backup subaccount at apply (terraform_data.backup_key, the box's install-ssh-key over the subaccount's password), never through the box resource: changing its ssh_keys recreates the box, data included.

Bootstrap

./scripts/bootstrap.sh --repo git@github.com:<you>/sekkeizu.git --git-crypt-key <file>   # see --help

Idempotent: on an already configured machine it skips what is done and ends with a switch. The shell part only installs Nix; everything else is scripts/bootstrap.nim.

Identity

The only file meant to be edited per-user is modules/meta/owner.nix: the values of kiso's options (account name, display name, email, the FIDO2 (YubiKey/Thetis) SSH keys used both to log in and to sign commits, where this repo is cloned, state versions).

To change kiso itself: edit ~/repositories/kiso, test with nix run .#switch -- --override-input scorsi-kiso path:$HOME/repositories/kiso, push it, then nix flake update scorsi-kiso here and commit flake.lock. kiso is public: nothing about these machines goes there.

Neovim: kanna

The Neovim config is its own repo and flake, kanna, consumed as the input scorsi-kanna (from Forgejo, GitHub mirror for recovery). Feature kanna: the config from the store, frozen with flake.lock. Feature kanna-dev (jiban): ~/.config/nvim links to the clone in ~/repositories/kanna (sekkeizu.reposDir), so Lua edits apply without a rebuild. Nix changes in kanna: see its README (--override-input scorsi-kanna path:…, then nix flake update scorsi-kanna).

About

設計図 — my homelab blueprint: nix-darwin and NixOS hosts, services, networking and secrets in one Nix flake (mirror of my Forgejo)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages