moving minipc2 services to nix

This commit is contained in:
ari committed 2026-08-27 15:15:06 -04:00
1 parent a9aaae3da9
commit 2a2bdd0b4b
9 files changed
+112 -13

No files matched your search

+2
View File
@@ -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
+25
View File
@@ -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 = {
@@ -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:
@@ -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
@@ -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 = { };
@@ -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/<group>/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/<group>/`. Use absolute paths (e.g. another
agenix secret path) or inline `environment:` instead.
- Create the secret with `skyg encrypt <secret-name>`.
---
## Limitations
- **One unit per group.** No per-container systemd units. Use `docker compose logs` for
+4
View File
@@ -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 ];
}
Binary file not shown.
Binary file not shown.