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.helm.mkChartAttrs#
Type: mkChartAttrs :: Path -> AttrSet
Walk a directory tree and import all default.nix
to download helm charts.
The default.nix
needs to have the following format:
{
repo = "https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts";
chart = "csi-driver-nfs";
version = "4.7.0";
chartHash = "sha256-EU2qaZglUU3vxa41l1p/2yBscksIhYMr8kSgH8t0vL8=";
}
dir
-
Path to a directory containing the correct directory structure described above.
Example:
mkChartAttrs ./charts
=> {
kubernetes-csi = {
csi-driver-nfs = lib.helm.downloadHelmChart {
repo = "https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts";
chart = "csi-driver-nfs";
version = "4.7.0";
chartHash = "sha256-EU2qaZglUU3vxa41l1p/2yBscksIhYMr8kSgH8t0vL8=";
};
};
}
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.fromOctal#
Type: fromOctal :: String -> Integer
Parse an octal representation of a number and convert into a decimal number. This can be useful when having to represent permission bits in a resource as nix has no support for representing octal numbers.
octal
-
String representation of the octal number to parse.
Example:
fromOctal "0555"
=> 365
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";
};
};
}