Skip to content

Libary Functions#

The argument lib is passed to each module in nixidy. This is the standard nixpkgs library extended with the following functions.

lib.helm.downloadHelmChart#

Type: downloadHelmChart :: AttrSet -> Derivation

Downloads a helm chart from a helm registry.

This is re-exported directly from farcaller/nix-kube-generators.

lib.helm.buildHelmChart#

Type: buildHelmChart :: AttrSet -> Derivation

Templates a helm chart with provided values and creates a derivation with the output.

This is re-exported directly from farcaller/nix-kube-generators.

lib.helm.getChartValues#

Type: getChartValues :: Derivation -> AttrSet

Parse the default values file shipped with the helm chart.

chart

Derivation containing helm chart. Usually output of lib.helm.downloadHelmChart.

Example:

getChartValues (lib.helm.downloadHelmChart {
    repo = "https://argoproj.github.io/argo-helm/";
    chart = "argo-cd";
    version = "5.51.4";
    chartHash = "sha256-LOEJ5mYaHEA0RztDkgM9DGTA0P5eNd0SzSlwJIgpbWY=";
})
=> {
  server.replicas = 1;
  controller.replicas = 1;
  # ...
}

lib.kustomize.buildKustomization#

Type: buildKustomization :: AttrSet -> Derivation

Builds a kustomization and creates a derivation with the output.

structured function argument

name

Name is only used for derivation name.

src

Derivation containing the kustomization entrypoint and all relative bases that it might reference.

path

Relative path from the base of src to the kustomization folder to render.

namespace

Override namespace in kustomization.yaml.

Example:

buildKustomization {
  name = "argocd";
  src = pkgs.fetchFromGitHub {
    owner = "argoproj";
    repo = "argo-cd";
    rev = "v2.9.3";
    hash = "sha256-GaY4Cw/LlSwy35umbB4epXt6ev8ya19UjHRwhDwilqU=";
  };
  path = "manifests/cluster-install";
  namespace = "argocd";
}
=> /nix/store/7i52...7pww-kustomize-argocd

lib.kube.fromYAML#

Type: fromYAML :: String -> [AttrSet]

Parses a YAML document string into a list of attribute sets.

This is re-exported directly from farcaller/nix-kube-generators.

yaml

String with a yaml document.

Example:

fromYAML ''
  apiVersion: v1
  kind: Namespace
  metadata:
    name: default
  ---
  apiVersion: v1
  kind: Namespace
  metadata:
    name: kube-system
''
=> [
  {
    apiVersion = "v1";
    kind = "Namespace";
    metadata.name = "default";
  }
  {
    apiVersion = "v1";
    kind = "Namespace";
    metadata.name = "kube-system";
  }
]

lib.kube.removeLabels#

Type: removeLabels :: [String] -> AttrSet -> AttrSet

Removes labels from a Kubernetes manifest.

labels

List of labels that should be removed

manifest

Kubernetes manifest

Example:

removeLabels ["helm.sh/chart"] {
  apiVersion = "v1";
  kind = "ConfigMap";
  metadata = {
    name = "argocd-cm";
    labels = {
      "app.kubernetes.io/name" = "argocd-cm";
      "helm.sh/chart" = "argo-cd-5.51.6";
    };
  };
}
=> {
  apiVersion = "v1";
  kind = "ConfigMap";
  metadata = {
    name = "argocd-cm";
    labels = {
      "app.kubernetes.io/name" = "argocd-cm";
    };
  };
}

lib.kube.namespace#

Type: namespace :: String -> AttrSet -> AttrSet

Create a Kubernetes namespace manifest. This will create a manifest in Kubernetes format so if you want to use it for application's resources it should be then parsed with lib.resources.fromManifests.

name

Name of the namespace manifest to create.

structured function argument

annotations

Optional annotations to add to the namespace manifest. This should be an attribute set.

labels

Optional labels to add to the namespace manifest. This should be an attribute set.

Example:

namespace "default" {
  labels = {
    "pod-security.kubernetes.io/enforce" = "privileged";
  };
}
=> {
  apiVersion = "v1";
  kind = "Namespace";
  metadata = {
    name = "default";
    labels = {
      "pod-security.kubernetes.io/enforce" = "privileged";
    };
  };
}

lib.kube.configMap#

Type: configMap :: String -> AttrSet -> AttrSet

Create a Kubernetes config map manifest. This will create a manifest in Kubernetes format so if you want to use it for application's resources it should be then parsed with lib.resources.fromManifests.

name

Name of the config map manifest to create.

structured function argument

data

Attribute set of data to put in the config map.

namespace

Optional namespace to add to the config map manifest.

annotations

Optional annotations to add to the namespace manifest. This should be an attribute set.

labels

Optional labels to add to the namespace manifest. This should be an attribute set.

Example:

configMap "my-config" {
  namespace = "default";
  data."data.txt" = "Hello world!";
}
=> {
  apiVersion = "v1";
  kind = "ConfigMap";
  metadata = {
    name = "my-config";
    namespace = "default";
  };
  data = {
    "data.txt" = "Hello world!";
  };
}

lib.kube.secret#

Type: configMap :: String -> AttrSet -> AttrSet

Create a Kubernetes secret manifest. This will create a manifest in Kubernetes format so if you want to use it for application's resources it should be then parsed with lib.resources.fromManifests.

Danger

Due to the nature of nixidy this resource will be rendered to YAML and stored in cleartext in git.

Using this resource for actual secret data is discouraged.

name

Name of the secret manifest to create

structured function argument

data

Attribute set of data to put in the config map. Values should be base64 encoded.

stringData

Attribute set of data to put in the config map. Values should be in cleartext.

namespace

Optional namespace to add to the config map manifest.

annotations

Optional annotations to add to the namespace manifest. This should be an attribute set.

labels

Optional labels to add to the namespace manifest. This should be an attribute set.

Example:

secret "my-secret" {
  namespace = "default";
  stringData."data.txt" = "Hello world!";
}
=> {
  apiVersion = "v1";
  kind = "Secret";
  metadata = {
    name = "my-secret";
    namespace = "default";
  };
  stringData = {
    "data.txt" = "Hello world!";
  };
}

lib.kube.service#

Type: service :: String -> AttrSet -> AttrSet

Create a Kubernetes service manifest. This will create a manifest in Kubernetes format so if you want to use it for application's resources it should be then parsed with lib.resources.fromManifests.

name

Name of the service manifest to create.

structured function argument

type

Type of service to create. Defaults to ClusterIP.

selector

Label selector to match pods that this service should target. This should be an attribute set.

ports

Ports this service should have. This should be an attribute set (see example).

namespace

Optional namespace to add to the config map manifest.

annotations

Optional annotations to add to the namespace manifest. This should be an attribute set.

labels

Optional labels to add to the namespace manifest. This should be an attribute set.

Example:

service "nginx" {
  namespace = "default";
  selector.app = "nginx";
  ports.http = {
    port = 80;
  };
}
=> {
  apiVersion = "v1";
  kind = "Service";
  metadata = {
    name = "nginx";
    namespace = "default";
  };
  spec = {
    type = "ClusterIP"; # Default
    selector.app = "nginx";
    ports = [
      {
        name = "http";
        port = 80;
        protocol = "TCP"; # Default
      }
    ];
  };
}