Update modules/server/containers/default.nix
This commit is contained in:
@@ -2,25 +2,21 @@
|
|||||||
let
|
let
|
||||||
serverCfg = config.syscfg.server;
|
serverCfg = config.syscfg.server;
|
||||||
builder = import ./builder.nix { inherit config lib pkgs serverCfg; };
|
builder = import ./builder.nix { inherit config lib pkgs serverCfg; };
|
||||||
enabledConfigs = lib.filterAttrs (name: c: c.enable) serverCfg.containers;
|
|
||||||
containerSetsList = lib.mapAttrsToList (name: containerCfg:
|
in{
|
||||||
let apps = import (./apps + "/${name}.nix") {inherit config pkgs lib containerCfg builder name;};
|
config = lib.mkMerge [{
|
||||||
|
syscfg.server.loadedContainers = lib.mapAttrs (name: containerCfg:
|
||||||
|
(import (./apps + "/${name}.nix")) { inherit config pkgs lib containerCfg builder name; }
|
||||||
|
) config.syscfg.server.containers;
|
||||||
|
} (lib.mkIf ( serverCfg.containers != {} ) (
|
||||||
|
let
|
||||||
|
appsList = builtins.attrValues config.syscfg.server.loadedContainers;
|
||||||
|
mergedContainers = lib.concatMapAttrs (appName: app:
|
||||||
|
lib.mapAttrs' (cName: cCfg: lib.nameValuePair "${appName}-${cName}" cCfg) app.containers
|
||||||
|
) config.syscfg.server.loadedContainers;
|
||||||
|
allPathConfigs = lib.concatMap (app: app.paths) appsList;
|
||||||
|
allCronsConfigs = lib.concatMap (app: app.cron) appsList;
|
||||||
in{
|
in{
|
||||||
name = name;
|
|
||||||
containers = lib.mapAttrs' (cName: cValue:
|
|
||||||
lib.nameValuePair "${name}-${cName}" cValue
|
|
||||||
) apps.containers;
|
|
||||||
paths = apps.paths or [];
|
|
||||||
setup = apps.setup or null;
|
|
||||||
cron = apps.cron or [];
|
|
||||||
}
|
|
||||||
) enabledConfigs;
|
|
||||||
mergedContainers = lib.attrsets.mergeAttrsList (lib.map(e: e.containers) containerSetsList);
|
|
||||||
allPathConfigs = lib.flatten (lib.map (e: e.paths) containerSetsList);
|
|
||||||
allCronsConfigs = lib.flatten (lib.map (e: e.cron or []) containerSetsList);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
config = lib.mkIf ( enabledConfigs != {} ) {
|
|
||||||
|
|
||||||
virtualisation.oci-containers = {
|
virtualisation.oci-containers = {
|
||||||
backend = "podman";
|
backend = "podman";
|
||||||
@@ -53,7 +49,7 @@ in
|
|||||||
startAt = "weekly";
|
startAt = "weekly";
|
||||||
};
|
};
|
||||||
} // lib.listToAttrs (lib.concatMap (containerSet:
|
} // lib.listToAttrs (lib.concatMap (containerSet:
|
||||||
if containerSet.setup != null then [{
|
if containerSet.setup.script != null then [{
|
||||||
name = "${containerSet.name}-setup";
|
name = "${containerSet.name}-setup";
|
||||||
value = {
|
value = {
|
||||||
description = "Run ${containerSet.name} setup";
|
description = "Run ${containerSet.name} setup";
|
||||||
@@ -70,12 +66,13 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}] else []
|
}] else []
|
||||||
) containerSetsList);
|
) appsList);
|
||||||
|
|
||||||
services.cron = {
|
services.cron = {
|
||||||
enable = true;
|
enable = true;
|
||||||
systemCronJobs = allCronsConfigs;
|
systemCronJobs = allCronsConfigs;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
}))];
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user