No description
  • Nix 98.2%
  • Shell 1.8%
Find a file
2026-05-09 15:49:27 +12:00
docs warning about env secrets, default to cookies lax, grafana enforce admin password, caddy redact query string secrets from logs 2026-05-09 14:43:02 +12:00
lib warning about env secrets, default to cookies lax, grafana enforce admin password, caddy redact query string secrets from logs 2026-05-09 14:43:02 +12:00
modules keep logs for, autoimport crowdsec headers 2026-05-09 15:49:27 +12:00
scripts Initial Commit: add scripts + docs 2026-01-17 12:57:10 +13:00
flake.lock Flake + missing notify doc & headscale 2026-01-24 14:25:43 +13:00
flake.nix add komodon tailscale ssh activation toogles to prevent failure, crowdsec register extra bouncers 2026-05-03 16:07:43 +12:00
README.md Add commonShell (starship, zsh + keybindings to match bash, fzf) 2026-04-25 15:43:29 +12:00

nixos-common

Shared NixOS library: three top-level option modules (per-host commonOptions, fleet-wide commonNetworking, a notification framework commonNotify), commonFlakeUpdater for scheduled flake.lock refresh, a host builder, and a set of opt-in server modules (commonAcmeDns, commonAlloy, commonAuthentik, commonBackup, commonBackupInternal, commonBeszel, commonCaddy, commonContainerBase, commonCrowdsec, commonGatus, commonGrafana, commonHardening, commonHeadplane, commonHeadscale, commonHomeAssistant, commonHomepage, commonLoki, commonMailRelay, commonMonitoring, commonNextcloud, commonNtfy, commonOnlyOffice, commonPostgres, commonPrometheus, commonRedis, commonRustdesk, commonTailscale, commonUptimeKuma, commonVaultwarden) plus a few shell helpers.

Layout

Top-level dirs split into server/ and desktop/ where the distinction is meaningful; truly shared content stays at the top level of each dir.

flake.nix
docs/
  future-design.md
  modules/                — per-module docs
  lib/                    — per-helper docs
  scripts/                — per-script docs
lib/
  default.nix             — aggregator (top-level + server + desktop)
  mkHost.nix              — shared host builder
  server/
    caddySnippets.nix     — Caddy vhost builders
    gatusEndpoints.nix    — Gatus endpoint + alert builders
    monitorTargets.nix    — neutral monitor spec → Gatus/Kuma renderers
    dumpDatabase.nix      — atomic mysqldump / pg_dump snippet
    authentik.nix         — Authentik OIDC-app / scope-mapping blueprint renderers
    backup/
      successReport.nix   — detailed backup-success report
      failureReport.nix   — detailed backup-failure report
  desktop/                — (empty)
modules/
  options.nix             — nixosModules.commonOptions
  networking.nix          — nixosModules.commonNetworking
  notify.nix              — nixosModules.commonNotify
  shell.nix               — nixosModules.commonShell
  flake-updater.nix       — nixosModules.commonFlakeUpdater
  server/
    authentik/
      default.nix         — nixosModules.commonAuthentik (options + aggregator)
      postgres.nix        — wires authentik DB through commonPostgres
      redis.nix           — wires authentik cache through commonRedis
      containers.nix      — server/worker/LDAP OCI containers + podman net
    backup/
      default.nix         — nixosModules.commonBackup
      notify.nix          — success/failure notification wiring
      internal.nix        — nixosModules.commonBackupInternal (pull-based)
    acme-dns.nix          — nixosModules.commonAcmeDns
    container-base.nix    — nixosModules.commonContainerBase
    alloy.nix             — nixosModules.commonAlloy
    beszel.nix            — nixosModules.commonBeszel
    caddy.nix             — nixosModules.commonCaddy
    crowdsec/
      default.nix         — nixosModules.commonCrowdsec
      bouncer.nix         — nftables bouncer + auto-register oneshot
    gatus/
      default.nix         — nixosModules.commonGatus
      dispatch.nix        — type/macro dispatch tables for checks
    grafana.nix           — nixosModules.commonGrafana
    hardening.nix         — nixosModules.commonHardening
    headplane.nix         — nixosModules.commonHeadplane (OCI)
    headscale.nix         — nixosModules.commonHeadscale
    home-assistant.nix    — nixosModules.commonHomeAssistant
    homepage.nix          — nixosModules.commonHomepage (OCI, one per view)
    loki.nix              — nixosModules.commonLoki
    mail-relay.nix        — nixosModules.commonMailRelay
    monitoring.nix        — nixosModules.commonMonitoring (Gatus/Kuma dispatch)
    nextcloud/
      default.nix         — nixosModules.commonNextcloud
      oidc.nix            — user_oidc login + provider registration
    ntfy.nix              — nixosModules.commonNtfy
    onlyoffice.nix        — nixosModules.commonOnlyOffice
    postgres.nix          — nixosModules.commonPostgres (shared DB layer)
    prometheus.nix        — nixosModules.commonPrometheus
    redis.nix             — nixosModules.commonRedis (instances attrset)
    rustdesk.nix          — nixosModules.commonRustdesk
    tailscale.nix         — nixosModules.commonTailscale
    uptime-kuma.nix       — nixosModules.commonUptimeKuma
    vaultwarden/
      default.nix         — nixosModules.commonVaultwarden
      oci.nix             — OCI-container backend
      native.nix          — services.vaultwarden (native) backend
  desktop/                — (empty)
pkgs/
  server/                 — (empty)
  desktop/                — (empty)
scripts/
  lib/
    common.sh             — shell helpers (source, no exec)
    sops.sh               — sops admin helpers
  server/
    colmena-checked.sh    — colmena wrapper gating on key passphrases
    check-deploy-keys.sh  — same audit, standalone (for pre-commit)
  desktop/                — (empty)

Per-feature docs

Each module / helper / script has a doc under docs/ explaining what it does, how to wire it, and any caveats. Source files keep only a short header pointing at the doc.

Consuming this flake

In the consumer's flake.nix, reference the repo by its git URL:

inputs.common.url = "git+ssh://git@forge.magnificent.nz/alister/nixos-common.git";

How to test against a consumer

To develop against a local checkout, point the input at a path instead:

inputs.common.url = "path:/home/alister/nixos-common";

Or one-shot without editing:

nixos-rebuild build --flake . \
  --override-input common path:/home/alister/nixos-common \
  --no-write-lock-file

Sanity-check the library evaluates

cd /home/alister/nixos-common
nix flake check

Conventions

  • File size budget for code/config (.nix, .sh): aim for under 200 lines excluding comments and blank lines; 250 is the hard ceiling. If a helper exceeds it, split into smaller files under a same-named subdirectory with a default.nix aggregator (e.g. lib/server/caddy/{primitives,composites,snippets,default}.nix).
  • Docs (.md) have no hard line limit — split a doc into meaningful sub-docs when it grows large enough that readers would benefit from focused files (rule of thumb: when distinct topics start competing inside one file, split by topic).
  • File header comments are short — what the file is and a link to its doc. Detailed prose lives in docs/.
  • Server / desktop splitlib/, modules/, pkgs/, scripts/ each have server/ and desktop/ subdirs for clearly one-sided content. Genuinely shared content stays at the top level of each dir.
  • X-Served-By and other diagnostic headers are opt-in (default off). The library never emits identity-bearing headers unless the consumer explicitly enables them with a non-PII label.
  • Mechanism, not policy. Modules expose options; consumer supplies the values. No hardcoded hostnames, IPs, sops paths, branding, or organisation names anywhere in this repo.

Consumer pattern: import-time data → specialArgs, not _module.args

Any value a consumer module needs while computing its imports — e.g. generating one container/import per entry in an inventory list, or importing a library module by path (inputs.common.nixosModules.X) — must be passed via specialArgs, never _module.args.

specialArgs are handed straight to the module function, so they exist during the import phase. _module.args only exist after the module fixpoint, so referencing one in imports causes infinite recursion ("... is not externally provided, so querying _module.args instead, requiring config"). Use _module.args only for values consumed inside config.

  • Plain lib.nixosSystem / mkHost: pass them in specialArgs (mkHost already does specialArgs = { inherit inputs vars; }).
  • colmena: use meta.specialArgs for fleet-wide values and meta.nodeSpecialArgs.<host> for per-host values. Do not put import-time inventory in a node's _module.args.