moving minipc2 services to nix
This commit is contained in:
1 parent
a9aaae3da9
commit
2a2bdd0b4b
9 files changed
+112
-13
No files matched your search
@@ -151,6 +151,8 @@
|
|||||||
nh
|
nh
|
||||||
agenix.packages.${system}.default
|
agenix.packages.${system}.default
|
||||||
age
|
age
|
||||||
|
# yq-go — YAML linting used by `skyg encrypt --yaml`
|
||||||
|
yq
|
||||||
home-manager.packages.${system}.home-manager
|
home-manager.packages.${system}.home-manager
|
||||||
rustc
|
rustc
|
||||||
cargo
|
cargo
|
||||||
|
|||||||
@@ -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)
|
# Scrypted backup timer (image auto-update handled by container-services autoUpdate)
|
||||||
skyg.server.timers = {
|
skyg.server.timers = {
|
||||||
scrypted-backups = {
|
scrypted-backups = {
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ Custom compose-style container service groups for systemd.
|
|||||||
6. `systemd.nix` builds oneshot units to manage the stack
|
6. `systemd.nix` builds oneshot units to manage the stack
|
||||||
7. `default.nix` wires tmpfiles, services, and paths together
|
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
|
## Adding a new feature
|
||||||
|
|
||||||
If adding a new per-service option:
|
If adding a new per-service option:
|
||||||
|
|||||||
@@ -24,17 +24,25 @@ in
|
|||||||
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
assertions = lib.optionals (enabledGroups != { }) [
|
assertions =
|
||||||
{
|
(lib.optionals (enabledGroups != { })
|
||||||
assertion = config.virtualisation.docker.enable or false
|
[{
|
||||||
|
assertion = config.virtualisation.docker.enable or false
|
||||||
|| config.virtualisation.podman.enable or false;
|
|| config.virtualisation.podman.enable or false;
|
||||||
message = ''
|
message = ''
|
||||||
skyg.nixos.common.container-services: at least one container runtime
|
skyg.nixos.common.container-services: at least one container runtime
|
||||||
must be enabled. Set skyg.nixos.common.containers.runtime (or enable
|
must be enabled. Set skyg.nixos.common.containers.runtime (or enable
|
||||||
virtualisation.docker / virtualisation.podman directly).
|
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
|
# Create tmpfiles rules for state dirs and file dirs
|
||||||
systemd.tmpfiles.rules =
|
systemd.tmpfiles.rules =
|
||||||
@@ -54,12 +62,17 @@ in
|
|||||||
(groupName: grpCfg:
|
(groupName: grpCfg:
|
||||||
let
|
let
|
||||||
fileVolumes = filesLib.mkFileVolumesForGroup groupName grpCfg;
|
fileVolumes = filesLib.mkFileVolumesForGroup groupName grpCfg;
|
||||||
composeFile = composeLib.mkComposeFile pkgs groupName grpCfg fileVolumes;
|
# An external compose file (e.g. an agenix secret) is used verbatim;
|
||||||
hasFiles = filesLib.getAllFiles grpCfg != { };
|
# 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
|
in
|
||||||
lib.nameValuePair
|
lib.nameValuePair
|
||||||
"container-services-${groupName}"
|
"container-services-${groupName}"
|
||||||
(systemdLib.mkSystemdService groupName grpCfg composeFile composeBin runtimeService hasFiles))
|
(systemdLib.mkSystemdService groupName grpCfg effectiveComposeFile composeBin runtimeService hasFiles))
|
||||||
enabledGroups
|
enabledGroups
|
||||||
// lib.foldAttrs lib.recursiveUpdate { } (
|
// lib.foldAttrs lib.recursiveUpdate { } (
|
||||||
lib.mapAttrsToList
|
lib.mapAttrsToList
|
||||||
|
|||||||
@@ -30,6 +30,24 @@
|
|||||||
description = "Seconds to wait for 'compose down' before forcibly killing containers.";
|
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 {
|
services = lib.mkOption {
|
||||||
description = "Container services in this group (maps to compose services: block).";
|
description = "Container services in this group (maps to compose services: block).";
|
||||||
default = { };
|
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
|
## Limitations
|
||||||
|
|
||||||
- **One unit per group.** No per-container systemd units. Use `docker compose logs` for
|
- **One unit per group.** No per-container systemd units. Use `docker compose logs` for
|
||||||
|
|||||||
@@ -23,4 +23,8 @@ in
|
|||||||
"secrets/hermes-env.age".publicKeys = [ ari fwdesk ];
|
"secrets/hermes-env.age".publicKeys = [ ari fwdesk ];
|
||||||
|
|
||||||
"secrets/iu-project.age".publicKeys = [ ari minipc1 ];
|
"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.
Reference in new issue
Block a user