From 2a2bdd0b4b6d8f925200d516b1950e258b7a7007 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 27 Aug 2026 15:15:06 -0400 Subject: [PATCH] moving minipc2 services to nix --- flake.nix | 2 + hosts/hl-minipc2.nix | 25 +++++++++++ .../containers/container-services/ABOUTME.md | 5 +++ .../containers/container-services/default.nix | 39 ++++++++++++------ .../containers/container-services/options.nix | 18 ++++++++ modules/nixos/common/containers/user-guide.md | 32 ++++++++++++++ secrets.nix | 4 ++ secrets/stack1.age | Bin 0 -> 928 bytes secrets/stack2.age | Bin 0 -> 1877 bytes 9 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 secrets/stack1.age create mode 100644 secrets/stack2.age diff --git a/flake.nix b/flake.nix index b13cd90..41779a3 100644 --- a/flake.nix +++ b/flake.nix @@ -151,6 +151,8 @@ nh agenix.packages.${system}.default age + # yq-go — YAML linting used by `skyg encrypt --yaml` + yq home-manager.packages.${system}.home-manager rustc cargo diff --git a/hosts/hl-minipc2.nix b/hosts/hl-minipc2.nix index ecfe85a..3c6ad01 100644 --- a/hosts/hl-minipc2.nix +++ b/hosts/hl-minipc2.nix @@ -81,6 +81,31 @@ }; }; + # Drawdb + skyg.nixos.common.container-services.drawdb = { + enable = true; + autoUpdate.enable = true; + services.drawdb = { + image = "ghcr.io/drawdb-io/drawdb:latest"; + ports = [ + "3000:80" + ]; + }; + }; + + age.secrets.stack1.file = ../secrets/stack1.age; + skyg.nixos.common.container-services.stack1 = { + enable = true; + autoUpdate.enable = true; + composeFile = config.age.secrets.stack1.path; + }; + age.secrets.stack2.file = ../secrets/stack2.age; + skyg.nixos.common.container-services.stack2 = { + enable = true; + autoUpdate.enable = true; + composeFile = config.age.secrets.stack2.path; + }; + # Scrypted backup timer (image auto-update handled by container-services autoUpdate) skyg.server.timers = { scrypted-backups = { diff --git a/modules/nixos/common/containers/container-services/ABOUTME.md b/modules/nixos/common/containers/container-services/ABOUTME.md index 3f25f83..af7f39c 100644 --- a/modules/nixos/common/containers/container-services/ABOUTME.md +++ b/modules/nixos/common/containers/container-services/ABOUTME.md @@ -23,6 +23,11 @@ Custom compose-style container service groups for systemd. 6. `systemd.nix` builds oneshot units to manage the stack 7. `default.nix` wires tmpfiles, services, and paths together +A group may instead set `composeFile` (e.g. to an agenix secret path) to use an +external, ready-made compose file verbatim instead of rendering from options — +useful for keeping sensitive definitions (NFS, env) out of version control. +See `user-guide.md` → "Secret Compose Definitions". + ## Adding a new feature If adding a new per-service option: diff --git a/modules/nixos/common/containers/container-services/default.nix b/modules/nixos/common/containers/container-services/default.nix index d0957a9..91dd447 100644 --- a/modules/nixos/common/containers/container-services/default.nix +++ b/modules/nixos/common/containers/container-services/default.nix @@ -24,17 +24,25 @@ in config = { - assertions = lib.optionals (enabledGroups != { }) [ - { - assertion = config.virtualisation.docker.enable or false + assertions = + (lib.optionals (enabledGroups != { }) + [{ + assertion = config.virtualisation.docker.enable or false || config.virtualisation.podman.enable or false; - message = '' - skyg.nixos.common.container-services: at least one container runtime - must be enabled. Set skyg.nixos.common.containers.runtime (or enable - virtualisation.docker / virtualisation.podman directly). - ''; - } - ]; + message = '' + skyg.nixos.common.container-services: at least one container runtime + must be enabled. Set skyg.nixos.common.containers.runtime (or enable + virtualisation.docker / virtualisation.podman directly). + ''; + }]) + ++ lib.mapAttrsToList + (name: grpCfg: + { + assertion = grpCfg.composeFile == null || grpCfg.services == { }; + message = + "skyg.nixos.common.container-services.${name}: set either composeFile OR services, not both."; + }) + enabledGroups; # Create tmpfiles rules for state dirs and file dirs systemd.tmpfiles.rules = @@ -54,12 +62,17 @@ in (groupName: grpCfg: let fileVolumes = filesLib.mkFileVolumesForGroup groupName grpCfg; - composeFile = composeLib.mkComposeFile pkgs groupName grpCfg fileVolumes; - hasFiles = filesLib.getAllFiles grpCfg != { }; + # An external compose file (e.g. an agenix secret) is used verbatim; + # otherwise render one from the group's options. + effectiveComposeFile = + if grpCfg.composeFile != null + then grpCfg.composeFile + else composeLib.mkComposeFile pkgs groupName grpCfg fileVolumes; + hasFiles = grpCfg.composeFile == null && filesLib.getAllFiles grpCfg != { }; in lib.nameValuePair "container-services-${groupName}" - (systemdLib.mkSystemdService groupName grpCfg composeFile composeBin runtimeService hasFiles)) + (systemdLib.mkSystemdService groupName grpCfg effectiveComposeFile composeBin runtimeService hasFiles)) enabledGroups // lib.foldAttrs lib.recursiveUpdate { } ( lib.mapAttrsToList diff --git a/modules/nixos/common/containers/container-services/options.nix b/modules/nixos/common/containers/container-services/options.nix index 1584aed..3a8b5b7 100644 --- a/modules/nixos/common/containers/container-services/options.nix +++ b/modules/nixos/common/containers/container-services/options.nix @@ -30,6 +30,24 @@ description = "Seconds to wait for 'compose down' before forcibly killing containers."; }; + composeFile = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + example = "config.age.secrets.my-compose.path"; + description = '' + Optional path to a ready-made compose file (e.g. an agenix-decrypted + secret such as config.age.secrets.my-compose.path) to use verbatim as + the group's compose.yml, instead of rendering one from + services/volumes/networks. + + When set, this group's services/volumes/networks/files blocks are + ignored; the external file must be a complete compose document. Use + this to keep a full definition (NFS devices, images, env, etc.) out + of version control while still deploying it through + container-services. + ''; + }; + services = lib.mkOption { description = "Container services in this group (maps to compose services: block)."; default = { }; diff --git a/modules/nixos/common/containers/user-guide.md b/modules/nixos/common/containers/user-guide.md index a8f2104..e8c7c85 100644 --- a/modules/nixos/common/containers/user-guide.md +++ b/modules/nixos/common/containers/user-guide.md @@ -129,6 +129,38 @@ Files are: --- +## Secret Compose Definitions (External `composeFile`) + +Keep a whole stack's definition out of version control by storing it in an +agenix secret and pointing the group at it: + +```nix +# In your host file +age.secrets.my-stack = { + file = ../secrets/my-stack.age; +}; +skyg.nixos.common.container-services.my-stack = { + enable = true; + composeFile = config.age.secrets.my-stack.path; +}; +``` + +When `composeFile` is set, the module: +- Uses that file **verbatim** as the group's `compose.yml` (copied to + `/var/lib/container-services//compose.yml` at startup, just like a + rendered one). +- Ignores this group's `services`/`volumes`/`networks`/`files` blocks — the + external file must be a complete compose document. +- Requires exactly one of `composeFile` or `services` to be set (assertion). + +Notes: +- `env_file:` entries in the external file resolve **relative to** + `/var/lib/container-services//`. Use absolute paths (e.g. another + agenix secret path) or inline `environment:` instead. +- Create the secret with `skyg encrypt `. + +--- + ## Limitations - **One unit per group.** No per-container systemd units. Use `docker compose logs` for diff --git a/secrets.nix b/secrets.nix index a29c45d..daacf63 100644 --- a/secrets.nix +++ b/secrets.nix @@ -23,4 +23,8 @@ in "secrets/hermes-env.age".publicKeys = [ ari fwdesk ]; "secrets/iu-project.age".publicKeys = [ ari minipc1 ]; + + # stack compose definition — minipc2 + "secrets/stack1.age".publicKeys = [ ari minipc2 ]; + "secrets/stack2.age".publicKeys = [ ari minipc2 ]; } diff --git a/secrets/stack1.age b/secrets/stack1.age new file mode 100644 index 0000000000000000000000000000000000000000..235a7d937054dfc0d3c7a56c465a237e20f1d263 GIT binary patch literal 928 zcmV;R17G}MXJsvAZewzJaCB*JZZ2y&T54!9XH`#kOHE9AWJ)whH)~~RK{Z8D3PWNm zS7c#$LMvl2XKOY`R%kX%R6Bnc4&8Zb4qVVVR$kxGh$9kL1$<|Vnkz4Wprd`3Z3K!-{OD0;H_+Wq)1xY zTAe*3Fp(Z$^28jFKj?33E`$$1_P|4=pwb>V5U{So#o{jLRb>S!lL^Obi-7sD&0x^>1f6iD^Zh80f*Iv5YcTDQkAiv!9i7+{0Pk<(@{zB(D_+F~D^B~j+ z@x@Qr9UCcDj~a40P(;TfEj^rcm=@uOyhr76^is&2~e7LAz?+M_?pd$Y*|}S(LIk|ApFZ zgrIrx>n06|QOiQbN9S4sK0P0QO{%UTxk!o4k-*H;#v(szo;?wY*t2DjC3I-c!?od&ot`P5RXDfZ;^z0 CON@~K literal 0 HcmV?d00001 diff --git a/secrets/stack2.age b/secrets/stack2.age new file mode 100644 index 0000000000000000000000000000000000000000..371a8cb52b9c65a9dcc30785f1690da7f847ed30 GIT binary patch literal 1877 zcmV-b2demCX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