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