create systemd unit only for enabled container

This commit is contained in:
pazpi 2024-08-28 21:04:18 +02:00
parent 7811654fb7
commit 3bdf838524

View file

@ -75,21 +75,11 @@ let
fi
'';
# flattenPodContainers =
# pods:
# mapAttrs' (
# podName: pod:
# mapAttrs' (
# containerName: container:
# nameValuePair "${podName}-${containerName}" (
# container
# # // {
# # inherit (pod) name;
# # extraOptions = (container.extraOptions or [ ]) ++ [ "--pod=${pod.name}" ];
# # }
# )
# ) (filterAttrs (n: v: v.enable or true) pod.containers)
# ) pods;
enabledContainers =
containers:
mapAttrs (name: container: removeAttrs container [ "enable" ]) (
filterAttrs (name: container: container.enable) containers
);
in
{
@ -113,37 +103,37 @@ in
systemd.services =
let
podServices = mapAttrs'
(
name: podDef:
nameValuePair "podman-pod-${name}" {
description = "Manage Podman pod: ${name}";
serviceConfig = {
Type = "oneshot";
ExecStart = "${createPodScript name podDef}";
};
path = [
pkgs.jq
pkgs.podman
];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
}
)
cfg;
containerServices = mapAttrs'
(
name: container:
nameValuePair "podman-${name}" {
after = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
requires = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
partOf = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
}
)
config.containers;
containers = enabledContainers config.containers;
podServices = mapAttrs' (
name: podDef:
nameValuePair "podman-pod-${name}" {
description = "Manage Podman pod: ${name}";
serviceConfig = {
Type = "oneshot";
ExecStart = "${createPodScript name podDef}";
};
path = [
pkgs.jq
pkgs.podman
];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
}
) cfg;
containerServices = mapAttrs' (
name: container:
nameValuePair "podman-${name}" {
after = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
requires = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
partOf = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
}
) containers;
in
podServices // containerServices;
};
}