nix/modules/utils/helper-functions.nix
2024-08-28 21:01:18 +02:00

42 lines
1.2 KiB
Nix

# 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;
};
}