Update modules/server/containers/default.nix

This commit is contained in:
2026-05-13 17:29:49 +02:00
parent 721838df2b
commit 0b02de0957

View File

@@ -15,14 +15,13 @@ in{
lib.mapAttrs' (cName: cCfg: lib.nameValuePair "${appName}-${cName}" cCfg) app.containers lib.mapAttrs' (cName: cCfg: lib.nameValuePair "${appName}-${cName}" cCfg) app.containers
) config.syscfg.server.loadedContainers; ) config.syscfg.server.loadedContainers;
allPathConfigs = lib.concatMap (app: app.paths) appsList; allPathConfigs = lib.concatMap (app: app.paths) appsList;
allSetupConfigs = lib.concatMap (app: if app.setup?script then [({name = app.name; envFile="";} // app.setup)] else []) appsList;
allCronsConfigs = lib.concatMap (app: app.cron) appsList; allCronsConfigs = lib.concatMap (app: app.cron) appsList;
in{ in{
virtualisation.oci-containers = { virtualisation.oci-containers = {
backend = "podman"; backend = "podman";
containers = mergedContainers; containers = mergedContainers;
}; };
system.activationScripts.container-setup-dirs = { system.activationScripts.container-setup-dirs = {
deps = [ "users" "groups" ]; deps = [ "users" "groups" ];
text = lib.concatStringsSep "\n" (map (cfg: text = lib.concatStringsSep "\n" (map (cfg:
@@ -48,25 +47,23 @@ in{
''; '';
startAt = "weekly"; startAt = "weekly";
}; };
} // lib.listToAttrs (lib.concatMap (containerSet: } // lib.listToAttrs (lib.concatMap (e: [{
if containerSet.setup.script != null then [{ name = "${e.name}-setup";
name = "${containerSet.name}-setup"; value = {
value = { description = "Run ${e.name} setup";
description = "Run ${containerSet.name} setup"; after = [ "podman-${e.name}-${e.trigger}.service" ];
after = [ "podman-${containerSet.name}-${containerSet.setup.trigger}.service" ]; wants = [ "podman-${e.name}-${e.trigger}.service" ];
wants = [ "podman-${containerSet.name}-${containerSet.setup.trigger}.service" ]; wantedBy = [ "multi-user.target" ];
wantedBy = [ "multi-user.target" ]; serviceConfig = {
serviceConfig = { Type = "oneshot";
Type = "oneshot"; TimeoutStartSec = "360s";
TimeoutStartSec = "360s"; EnvironmentFile = e.envFile;
EnvironmentFile = if (containerSet.setup ? envFile) then containerSet.setup.envFile else [ ]; ExecStart = e.script;
ExecStart = "${containerSet.setup.script}"; RemainAfterExit = true;
RemainAfterExit = true; User = "root";
User = "root";
};
}; };
}] else [] };
) appsList); }]) allSetupConfigs );
services.cron = { services.cron = {
enable = true; enable = true;