My nixos media server config.
  • Nix 71.7%
  • Python 23.4%
  • JavaScript 2.5%
  • Shell 2.4%
Find a file
2026-12-01 22:33:09 +01:00
dashboards fix: fill tablet screen with calendar popup 2026-11-17 15:41:01 +01:00
hosts/nixos-server Revert "feat(quiet): change time for parity rebuild" 2026-11-29 16:26:34 +01:00
modules chore(deps): update ghcr.io/cleanuparr/cleanuparr docker tag to v2.11.3 2026-12-01 22:33:09 +01:00
packages feat: automate dependency PRs and master deployments 2026-11-29 22:06:57 +01:00
secrets feat: add secrets 2026-11-29 22:27:12 +01:00
.gitattributes chore: add gitignore, gitattributes, and exclude .claude 2026-09-30 08:26:48 +02:00
.gitignore chore: remove dead comments 2026-10-13 14:26:27 +02:00
.sops.yaml refactor(secrets): derive the cloudflare env file from one cloudflare-dns-token 2026-10-01 19:26:48 +02:00
flake.lock fix: lock screen widgets 2026-12-01 17:11:54 +01:00
flake.nix fix: lock screen widgets 2026-12-01 17:11:54 +01:00
packages.nix fix: restore dependency tracking and coupled Tdarr updates 2026-11-29 22:27:12 +01:00
README.md feat: restrict habit management frontend to the VPN 2026-12-01 14:14:59 +01:00
renovate.json chore: distinguish SSH flake inputs in Renovate 2026-12-01 13:50:18 +01:00

nixos-server

Ryzen 2700X, RTX 3060, 48 GB

Layout

flake.nix                    nixosConfigurations.nixos-server, `versions`
packages.nix                 native application packages from independently locked inputs
hosts/nixos-server/          hardware config + site knobs (disks, subnet, what's enabled)
modules/options.nix          the `host.*` knobs
modules/system/              boot, network/firewall/wake-on-LAN, nix, users, ssh, tailscale
modules/hardware/            nvidia driver, CoolerControl fan curves, RGB off
modules/storage/             mergerfs union, snapraid parity, zfs fast pool, spin-down
modules/services/            media stack, immich, paperless, forgejo, microbin, dashboard, nginx, AI

Firewall: SSH, Plex, HTTPS (443) and Forgejo SSH (2222) are open; every other UI is LAN-only (host.lanCidr) or over Tailscale (tailscale0 is trusted).

Reverse proxy

nginx serves every UI at https://<app>.internal.steenblik.ch: the wildcard record points at the tailnet IP and nginx only allows LAN and tailnet sources. Hosts in public (modules/services/proxy.nix: Forgejo as git, Immich as photos, Paperless as documents, MicroBin as notes, the dashboard as server, Open WebUI as ai) are at https://<app>.steenblik.ch, through 443 forwarded on the router; cloudflare-dyndns keeps their A records current.

Certificates come from Let's Encrypt via Cloudflare DNS-01, so port 80 stays closed.

Habit tracker

habit-tracker-api is a remote flake input providing the F#/.NET 11 API at https://habits.steenblik.ch. Its NixOS module runs as htapi and connects to the local PostgreSQL database of the same name through peer authentication. Evolve applies schema migrations; habits are created and configured through the API.

The management frontend is at https://habits.internal.steenblik.ch and only accepts Tailscale VPN addresses. Sign in with the API token to create or edit habits and record today's values. The public hostname exposes only the token-authenticated widget API, script download, and health check.

Before deploying, create the role and database on the server:

sudo -u postgres createuser --no-superuser --no-createdb --no-createrole htapi
sudo -u postgres createdb --owner=htapi htapi

The server's GitOps deploy key needs read access to jblik/habit-tracker-api. Database provisioning, API setup, and step-by-step Scriptable instructions are in the API README.

Secrets

sops-nix: secrets/secrets.yaml is committed encrypted, each key becomes /run/secrets/<key> on the server, decrypted with its SSH host key. Recipients (your age key and the server's) are in .sops.yaml. Edit with nix shell nixpkgs#sops -c sops secrets/secrets.yaml, then commit and deploy.

Deploy

Edit on the Mac and commit (the flake only sees committed files), then build and switch on the server:

nix run nixpkgs#nixos-rebuild -- switch --flake .#nixos-server --target-host nixos-server --build-host nixos-server --use-substitutes --sudo --ask-sudo-password

Adding substitutes doesn't remove the overhead of evaluating locally. Better would be to evaluate on the server and switch there.

A bad generation can be rolled back with sudo nixos-rebuild switch --rollback, or by picking an older entry in the boot menu.

GitOps

modules/services/gitops runs Renovate hourly and checks master for deployment every five minutes. Renovate opens separate PRs assigned to jblik for each flake input, custom package source, fixed container tag, and imported Grafana dashboard. PR creation has no hourly or concurrency limit, so every available update can have its own open PR. It refreshes source hashes and flake.lock in the same PR. Flake inputs use explicit revisions; renovate-ref annotations select the branch each input follows. Tdarr's server and node share nixpkgs-tdarr and always update together. Immich's ML image follows the native Immich package version. Model selections under host.ai.models remain explicit choices.

Automerge is disabled. Review and merge the desired PR into protected master. The independent nixos-upgrade.service builds the committed configuration with its lock file and switches only after the build succeeds. It does not update inputs or reboot the server. Kernel changes take effect after a manual reboot. Activation runs outside Forgejo's runner so restarting Forgejo or the runner cannot kill its own deployment job. Polling needs Forgejo to be available to fetch the source.

This setup does not add PR build checks. A failed build leaves the previous generation running; activation errors can leave partial changes and need inspection. The existing Alertmanager UnitFailed rule emails about failed services, including Renovate and nixos-upgrade. A system rollback does not reverse service database migrations.

Before the first deployment:

  1. Create a dedicated Forgejo account named renovate, with full name and email configured, and give it write access to jblik/nixos-server. Create an API token with repository read/write, issue read/write, user read and organization read permissions. Restrict it to this repository where supported. Protect master against direct pushes from the bot; it needs to push only its feature branches.

  2. Create a GitHub token that can read public repositories for upstream release lookups. It does not need write access or access to private repositories.

  3. On the server, generate a dedicated key with no passphrase: ssh-keygen -t ed25519 -f ~/.ssh/gitops -C "nixos-server deployment". Add only the public key from ~/.ssh/gitops.pub to both nixos-server and server-dashboard under repository Settings → Deploy Keys, without write access.

  4. On a machine that already trusts Forgejo, obtain its saved host-key entry with ssh-keygen -F '[git.steenblik.ch]:2222'. Use that verified entry for gitops-known-hosts; do not accept an unverified key scanned over the network.

  5. Edit secrets/secrets.yaml with SOPS and add these four string values:

    Key Value
    renovate-token Forgejo bot API token
    renovate-github-token GitHub public repository lookup token
    gitops-ssh-key Entire private key from ~/.ssh/gitops, as a multiline string
    gitops-known-hosts Verified Forgejo host-key entry, as a multiline string

    SOPS decrypts them to root-owned files under /run/secrets. systemd supplies private copies to the services using credentials; the private key is never put in the Nix store. Renovate uses its API token for branches and PRs. Its Git GIT_ASKPASS script supplies username renovate and that token for HTTPS requests to git.steenblik.ch, including requests after redirects; deployment uses only the read-only SSH key. NixOS login authorizedKeys do not need changes.

  6. Merge this configuration and the encrypted secrets into remote master before the initial manual deployment using the command above. Otherwise the timer can redeploy the older remote configuration. The timers take over after that deployment.

  7. In Forgejo, verify your account email, enable email notifications, and watch jblik/nixos-server for issues and PRs. Forgejo's mailer uses the existing Apple SMTP credentials. PR assignments also appear in Forgejo's notification inbox. Send a test email from Forgejo's administration page to check delivery.

Check or run the services on the server:

systemctl list-timers renovate nixos-upgrade
sudo systemctl start renovate.service
journalctl -u renovate -u nixos-upgrade -n 100
nixos-version --revision

If the dashboard reports Error updating branch, inspect the Renovate journal for the underlying Git or post-upgrade command error. A successful dashboard update only confirms API access; Git branch publication authenticates separately. After changing the Renovate service configuration, deploy it before rerunning the service.

Stop nixos-upgrade.timer before a manual rollback so it does not redeploy master: sudo systemctl stop nixos-upgrade.timer. Start it again once master is corrected.

Storage

  • Bulk: one XFS filesystem per HDD at /mnt/diskN, merged by mergerfs into /data, SnapRAID parity once parityFiles is set.
  • Fast: ZFS mirror fast on the two SATA SSDs. Service state under /var/lib, one dataset per service (host.storage.fastDatasets.snapshot), snapshotted hourly by sanoid; regeneratable data (Immich and Paperless thumbnails, transcodes) in fastDatasets.noSnapshot.

/data: torrents/{tv,movies}, media/{tv,movies} (imports are hardlinks). /scratch/{incomplete,transcode} (NVMe, off the pool): in-progress downloads and the Plex/Tdarr transcode cache. SABnzbd downloads and unpacks on NVMe under /scratch/usenet/{incomplete,complete}. Sonarr and Radarr import completed jobs into /data/media/{tv,movies} and remove the source after a successful import. Usenet downloads do not need to stay for seeding.

Plex's generated Media directory is bind-mounted from /data/plex-media on the HDDs. Media Preview Generator runs in Podman with the RTX 3060; its UI is on port 8280.

Maintenance

host.maintenance.enable defaults to false and provides the default enable value for each task: host.maintenance.keepCool, host.maintenance.qbittorrent, host.maintenance.tdarr, and host.maintenance.mediaPreviewGenerator. An explicit per-task enable overrides the global default. Tasks disabled in Nix remain disabled regardless of the Home Assistant controls.

Nix provides input_boolean.server_maintenance, the four shell_command.server_maintenance_<task> commands (keep_cool, seeding, tdarr, previews), and the permissions they need. There are no maintenance schedules. The maintenance automations are managed in Home Assistant's UI and stored in its writable automations.yaml, included by modules/services/home-assistant.nix:

  • Server maintenance: determine activity sets the maintenance boolean when Rocky's dock is drying, Rocky is cleaning, both person.jacob and person.sophie are confirmed away, or the bedroom door is closed and everyone home is asleep. The sleep condition uses input_boolean.jacob_asleep and input_boolean.sophie_asleep only for the people currently home, with no time restriction. Unknown or unavailable presence is not treated as away.
  • Server maintenance: apply activity passes the maintenance boolean to all four task commands. Both automations reconcile on Home Assistant startup and automation reload; the decision also follows its input states, and application follows the maintenance boolean.

Opening the bedroom door ends the sleep reason; maintenance stays active if any other reason remains. Location automations control lights and Rocky without writing the maintenance boolean.

Commands write each requested state atomically under /var/lib/server-maintenance/ and start the task oneshot through narrowly scoped polkit permissions. Application startup and torrent-completion hooks read that same local state; before the first state is written, maintenance is off. Last requested states survive restarts. Failed task services retry after ten seconds. Home Assistant must stay running to react to changes in the household.

The media tasks each have a default.nix and maintenance.py under modules/services/media/. Shared task launchers live in modules/services/maintenance/. Keep cool's script and configuration live together in modules/hardware/fans/. Manual fan controls remain in the dashboard's Fans card. Manual changes clear maintenance ownership through a separate invocation of the fan script, so later reconciliation of the same active period preserves the manual choice. Ownership state under /var/lib/coolercontrol-maintenance/ survives service restarts.

Separate task services pause/unpause the Tdarr node, set preview CPU workers to host.maintenance.mediaPreviewGenerator.cpuWorkers (default 2) or zero, and restrict completed torrents to active maintenance periods. No maintenance polling timers are used.

Tdarr and preview workers finish current files when paused/reduced; preview GPU workers stay available. The preview API's CPU count control requires a single dedicated CPU worker group; split or mixed CPU/GPU groups must be adjusted in the preview application's Workers settings. The task service reads the preview application's existing auth.json token locally, without exposing it to the dashboard. Keep cool retains manual fan-mode ownership within an active maintenance period.

qBittorrent runs its completion launcher as qbittorrent, reading the current maintenance state rather than embedding activation rules in the completion command. Reconciliation runs as the same user through the existing host-side WebUI proxy. Completion hooks use the VPN namespace's local WebUI and need no dashboard connectivity. A shared lock and seeding-stopped.json live in the existing writable qBittorrent profile subdirectory; this operational ownership state survives restarts. Only torrents stopped by the script are resumed; manual stops and ratio/time limits remain respected. There is no completion marker or systemd path watch, and qBittorrent's sandbox is unchanged. Applications may still save their own settings.

The server configuration and dashboard changes must be deployed together. For local validation, use --override-input server-dashboard path:/Users/jblik/projects/server-dashboard; the checked-in flake input continues to reference the published dashboard revision.

Services

Service Port Runs as
Plex 32400 native
Media Preview Generator 8280 Podman, NVIDIA GPU
Sonarr / Radarr / Bazarr 8989 / 7878 / 6767 native
FlareSolverr 8191 (localhost) native
Prowlarr (prowlarr.internal.steenblik.ch) 9696 native
qBittorrent 8080 native
SABnzbd (sabnzbd.internal.steenblik.ch) 8085 (localhost) native
Tdarr 8265 (UI), 8266 (server) native, GPU node
Cleanuparr 11011 podman container
Pulsarr 3003 podman container
Maintainerr 6246 podman container
Immich (photos.steenblik.ch) 2283 (localhost) native, ML on 3004 as a podman CUDA container
Paperless-ngx (documents.steenblik.ch) 28981 (localhost) native, + Tika 9998, Gotenberg 3001, PostgreSQL
Forgejo (git.steenblik.ch) 3000 (localhost), SSH 2222 native
Forgejo runner — native, Podman jobs with per-job Docker-in-Docker
MicroBin (notes.steenblik.ch) 8081 (localhost) native
CoolerControl 11987 (localhost) native
Dashboard (server.steenblik.ch) 5180 / 5181 (localhost) native, from the server-dashboard flake
node_exporter 9100 (localhost) native
Prometheus / Alertmanager (mails alerts) 9090 / 9093 (localhost) native
Grafana (grafana.internal.steenblik.ch) 3002 (localhost) native
Tailscale (exit node) — native
Ollama + Open WebUI (ai.steenblik.ch) 11434 / 8082 (localhost) native, Ollama on the RTX 3060

Prowlarr runs at https://prowlarr.internal.steenblik.ch, accessible from the LAN and tailnet through the existing wildcard DNS and TLS certificate. Before deploying it for the first time, create its snapshotted state dataset on the server:

sudo zfs create -o mountpoint=legacy fast/prowlarr

Configure indexers and application connections in Prowlarr's UI. Local Sonarr and Radarr URLs are http://127.0.0.1:8989 and http://127.0.0.1:7878; the shared FlareSolverr is at http://127.0.0.1:8191.

Usenet

SABnzbd is at https://sabnzbd.internal.steenblik.ch, proxying its loopback-only UI on port 8085. Before its first deployment, create its snapshotted state dataset:

sudo zfs create -o mountpoint=legacy fast/sabnzbd

Enter Usenet provider servers and credentials in SABnzbd's UI, using the provider's TLS settings. Configure Usenet indexers in Prowlarr and sync them to Sonarr/Radarr. Provider credentials and SABnzbd's generated API key remain in its private state directory; UI settings persist across rebuilds except for the paths and categories managed here.

The sonarr-sabnzbd and radarr-sabnzbd services automatically configure the local SABnzbd download client through the application APIs. They enable Completed Download Handling and removal after successful import, with categories tv and movies. Completed jobs stay under /scratch/usenet/complete/{tv,movies} until imported into the existing bulk-drive libraries; no remote path mapping is needed. The services retry while the application APIs are starting. Check setup with:

systemctl status sabnzbd sonarr-sabnzbd radarr-sabnzbd
journalctl -u sonarr-sabnzbd -u radarr-sabnzbd -b

VPN and torrent monitoring

With the dashboard and media stack enabled, speedtest-nordvpn.timer runs an Ookla speedtest hourly, offset by 30 minutes from the host speedtest. It runs inside qBittorrent's network namespace and binds to nordvpn, using the same VPN DNS configuration. To run it manually after deploying:

sudo systemctl start speedtest-nordvpn.service
journalctl -u speedtest-nordvpn -n 50

Grafana's NordVPN dashboard compares hourly VPN and host speedtest results and shows VPN latency, jitter, packet loss, and the age of the last result. The latest speedtest has its own card, separate from continuous traffic. The Server dashboard also shows the latest host speedtest, its age, and the hourly result history.

Both dashboards refresh every five seconds and include current traffic cards and continuous traffic graphs. Host traffic uses the existing node_exporter counters for physical Ethernet and Wi-Fi interfaces; it includes LAN transfers and encrypted VPN traffic, so it is not a measurement of internet-only traffic or available bandwidth. nordvpn-traffic.timer reads the VPN interface's byte counters inside qBittorrent's network namespace every five seconds, independently of the qBittorrent API. This adds a small local counter read, with no test traffic or additional network requests. Rates are averaged over Grafana's query interval. VPN traffic is hidden once collection is more than 30 seconds old; its collection age is shown separately. Speedtests continue to measure available bandwidth hourly.

The qBittorrent dashboard shows transfer rates, session and all-time totals, share ratio, torrent counts by state, remaining downloads, free download space, peers, DHT nodes, and connection status. qbittorrent-metrics.timer collects every 30 seconds through the local API inside the VPN namespace, using the API key already managed in qBittorrent's profile. No additional credentials or public metrics port are needed. The collectors publish through node_exporter's textfile collector. If a collection fails, its last successful result remains; check the age panels and service journals when interpreting old readings.

Home Assistant

Home Assistant runs natively through services.home-assistant, enabled by host.home-assistant.enable. Nix manages the service, integration dependencies, base configuration and HomeKit Bridge. Pairings and credentials are managed in the UI and stored under /var/lib/hass; this directory is not yet a dedicated snapshotted ZFS dataset.

Matter Server runs natively alongside Home Assistant, with persistent pairings under /var/lib/private/matter-server. In Home Assistant's Matter integration, use ws://127.0.0.1:5580/ws. The WebSocket endpoint listens only on localhost. Home Assistant and Matter Server have independent unstable-home-assistant and nixpkgs-matter-server inputs.

TCP 8123 (UI), TCP 21063 (HomeKit), UDP 5353 (mDNS discovery) and UDP 5540 (Matter) are allowed from host.lanCidr. mDNS and Matter are also allowed from IPv6 link-local and unique-local addresses for Thread devices. Keep the server, hubs and iPhone on the same LAN for pairing; Thread devices need IPv6 connectivity through a Thread border router.

Chromebook display

The Chromebook automations control brightness through the Android Companion app. Wake sets brightness to 80/255, enables keep-screen-on, then enables automatic brightness. Sleep disables automatic brightness and sets brightness to 0. Wake requires someone home and either more than 15 lux for two seconds or Monkey on; sleep runs when everyone leaves or below 10 lux for ten seconds with Monkey off. Between 10 and 15 lux, brightness stays unchanged.

Browser Mod remains necessary for the dashboard's weather, calendar and vacuum popups, independently of screen control. The restore automation expects the Companion app in the foreground, so Fully Kiosk Browser can cause repeated wake commands while the wake conditions hold.

Dashboard cards

Home Assistant and its custom integrations use the independently locked unstable-home-assistant unstable input. Nix installs Atomic Calendar Revive, Flightradar24 Card, and Music Assistant Player Card, plus the Flightradar24 and Music Assistant Queue Actions integrations. Music Assistant Player Card is packaged from its pinned release asset in packages/mass-player-card.nix; the other cards above come from Nixpkgs. HACS is not needed.

After deploying with the command above:

  1. In Settings → Devices & services → Add integration, add Flightradar24 and configure the centre and radius of the monitored area.
  2. Configure the official Music Assistant integration as described below. Accept discovery of Music Assistant Queue Actions, or add it through Add integration if it is not discovered.
  3. Configure your calendar provider in Home Assistant so a calendar.* entity exists. Providers with additional Python dependencies also need their integration name in services.home-assistant.extraComponents.
  4. Reload the browser, edit your dashboard and select Add card. Search for Atomic Calendar Revive, Flightradar24 Card, or Music Assistant Player Card. Select your calendar, the Flightradar24 current-in-area sensor, or a Music Assistant player entity respectively. The music card includes a queue tab and queue controls.

Nix registers JavaScript resources under /local/nixos-lovelace-modules/ and manages them in YAML; dashboard layouts remain editable in the UI. Add resource declarations in Nix rather than the Resources UI, and avoid installing duplicate copies through HACS. Update the packaged integrations and cards with a Renovate PR for unstable-home-assistant; the local music card has its own PR including its version and asset hash.

AI Models

host.ai.models in hosts/nixos-server/default.nix, as Ollama tags (https://ollama.com/library). chat is Open WebUI's only selectable chat model and Paperless' model, embedding is for document search in both, any other name (code) is only pulled for API clients. Open WebUI's connection filter hides the coding and embedding models from its model selector; embeddings remain available internally for document search. Deploy pulls new tags and deletes dropped ones; journalctl -fu ollama-model-loader shows the download. A model is loaded on first request and unloaded after 5 minutes idle.

Clients

The key is sops -d --extract '["ai-api-key"]' secrets/secrets.yaml.

  • OpenAI-compatible (Continue, Zed, opencode, Codex, JetBrains AI, …): base URL https://ai.steenblik.ch/v1, the key as API key, a model tag as model.
  • Claude Code:
    ANTHROPIC_BASE_URL=https://ai.steenblik.ch ANTHROPIC_AUTH_TOKEN=<key> \
      ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3:8b claude --model qwen3-coder:30b
    

Package versions

nix eval --json .#versions | jq   # each package: version here, version in nixos-26.05

Each standalone native application has its own nixpkgs-<app> input and lock entry, including applications on stable. The nixpkgs input controls the OS and shared system tools. The dashboard already has its own server-dashboard input. Container images are configured separately in modules/services/media/containers.nix; Immich's ML image follows its application version.

Normally, merge the application's Renovate PR. To update a flake input manually, look up a commit on its tracked branch, replace only that input's revision in flake.nix, then regenerate the lock file:

nix flake metadata github:NixOS/nixpkgs/nixos-26.05 --refresh --json | jq -r .locked.rev
# Put the selected revision in the desired input URL before locking.
nix flake lock
nix eval --json .#versions | jq

With explicit revisions, nix flake update <input> alone cannot advance that input. Keep the renovate-ref annotation aligned with the branch you intend to track.

Paperless' package, NixOS service module, Tika and Gotenberg use that same input, while Gotenberg's Chromium and LibreOffice helpers use the system packages. PostgreSQL and Redis keep separate pins because they are shared with Immich. Once Paperless' locked revision includes the torchcodec test fix, remove the extraPythonPackageOverrides override in packages.nix. Immich and every other application keep their existing locks. Tdarr's server and node share nixpkgs-tdarr and update together in one PR.

Update the nixpkgs revision to update the OS without advancing application pins. Build and deploy as described above after checking the selected version.

Back to plain nixpkgs

The goal is no custom version or build overrides. Independent application pins stay so each application can be updated separately. Once stable nixpkgs has caught up:

  1. Update only the OS input revision, or choose a commit from the next release and update the nixpkgs revision and its renovate-ref annotation together.
  2. nix eval --json .#versions | jq: an application can move to stable when its nixpkgs version is the same or newer than here. Never go to an older one.
  3. Change the application's revision and renovate-ref annotation to the stable branch and run nix flake lock. Keep its package selection in packages.nix, but remove any custom overrides stable no longer needs, such as Paperless' torchcodec fix. For Paperless, remove the disabledModules/imports lines in modules/services/paperless/default.nix once the OS module handles 3.x.
  4. Build and deploy (see Deploy). Check the service starts and its journal shows no database migration errors. Commit.