From 9d6925d72019b32fb08543d93a3d54fdd16e3d76 Mon Sep 17 00:00:00 2001 From: pazpi Date: Sun, 25 Aug 2024 22:04:45 +0200 Subject: [PATCH] WIP: error infinite recursion for oci-container --- modules/virtualisation/podman-pod.nix | 85 ++++++++++++++++++--------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/modules/virtualisation/podman-pod.nix b/modules/virtualisation/podman-pod.nix index 788382b..2127cc6 100644 --- a/modules/virtualisation/podman-pod.nix +++ b/modules/virtualisation/podman-pod.nix @@ -6,37 +6,37 @@ with lib; let cfg = config.services.podmanPods; + # Get the options from the original oci-containers module + containerOptions = (filterAttrs (n: v: n != "definition") + config.virtualisation.oci-containers.containers.type.getSubOptions); + + # Add our enable option + extendedContainerOptions = containerOptions // { + enable = mkEnableOption "Enable this container"; + }; + podOptions = { name, config, ... }: { options = { + name = mkOption { type = types.str; description = "Name of the pod"; }; + ports = mkOption { type = types.listOf types.str; default = [ ]; description = "List of port mappings (e.g. ['8080:80'])"; }; + containers = mkOption { - type = types.attrsOf ( - types.submodule - { - options = { - image = mkOption { - type = types.str; - description = "Docker image for the container"; - }; - extraOptions = mkOption { - type = types.listOf types.str; - default = [ ]; - description = "Additional options for the container"; - }; - }; - } - ); + type = types.attrsOf (types.submodule { + options = extendedContainerOptions; + }); default = { }; - description = "Containers to run in the pod"; + description = "Attribute set of OCI container configurations for this set"; }; + }; }; @@ -72,6 +72,13 @@ let create_pod fi ''; + + enabledContainers = lib.flatten (mapAttrs + (podName: podConfig: + filterAttrs (name: value: value.enable or true) podConfig.containers + ) + cfg); + in { options.services.podmanPods = mkOption { @@ -86,18 +93,38 @@ in environment.systemPackages = [ pkgs.jq ]; - virtualisation.oci-containers.containers = listToAttrs (flatten (mapAttrsToList - (podName: podDef: - mapAttrsToList - (containerName: containerDef: - nameValuePair "${podName}-${containerName}" ({ - inherit (containerDef) image; - extraOptions = [ "--pod=${podName}" ] ++ containerDef.extraOptions; - }) - ) - podDef.containers - ) - cfg)); + virtualisation.oci-containers.containers = enabledContainers; + + # virtualisation.oci-containers.containers = listToAttrs (flatten (mapAttrsToList + # (podName: podDef: + # mapAttrs + # (containerName: containerDef: + # filterAttrs (attrName: attrValue: attrName != "enable") containerDef + # # nameValuePair "${podName}-${containerName}" ({ + # # inherit (containerDef) image; + # # extraOptions = [ "--pod=${podName}" ] ++ containerDef.extraOptions; + # # }) + # ) + # podDef.containers + # ) + # cfg)); + + # virtualisation.oci-containers.containers = lib.flatten + # (mapAttrs + # (podName: podConfig: + # mapAttrs + # (containerName: containerConfig: + # filterAttrs (attrName: attrValue: attrName != "enable") containerConfig + # ) + # (filterAttrs (name: value: value.enable) podConfig.containers) + # ) + # (filterAttrs (podName: podConfig: podConfig.enable) cfg) + # ); + # mapAttrs + # (name: value: + # filterAttrs (n: v: n != "enable") value + # ) + # (filterAttrs (name: value: value.enable) cfg.containers); networking.firewall.allowedTCPPorts = flatten (mapAttrsToList (name: podDef: