diff --git a/modules/utils/helper-functions.nix b/modules/utils/helper-functions.nix new file mode 100644 index 0000000..29df32b --- /dev/null +++ b/modules/utils/helper-functions.nix @@ -0,0 +1,42 @@ +# helpers.nix +{ lib, config, ... }: + +let + # Function to add containers to a pod + addContainerToPod = + podName: containerSet: + let + modifyContainer = + container: + let + containerWithoutEnable = builtins.removeAttrs container [ "enable" ]; + updatedExtraOptions = (container.extraOptions or [ ]) ++ [ "--pod=${podName}" ]; + in + containerWithoutEnable // { extraOptions = updatedExtraOptions; }; + in + builtins.mapAttrs (name: modifyContainer) containerSet; + + # Function to process all containers in a structure + processContainers = + structure: structure // { containers = addContainerToPod structure.name structure.containers; }; +in +{ + options.helpers = { + addContainerToPod = lib.mkOption { + type = lib.types.anything; + default = null; + description = "Function to add a container to a pod."; + }; + processContainers = lib.mkOption { + type = lib.types.anything; + default = null; + description = "Function to process all containers in a structure."; + }; + }; + + config = { + # Expose the helper functions + helpers.addContainerToPod = addContainerToPod; + helpers.processContainers = processContainers; + }; +}