Module for common functions
This commit is contained in:
parent
34f11ee2fb
commit
6c700e2c5e
1 changed files with 42 additions and 0 deletions
42
modules/utils/helper-functions.nix
Normal file
42
modules/utils/helper-functions.nix
Normal file
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue