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
@@ -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 = { };
|
||||
|
||||
Reference in new issue
Block a user