mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-14 11:37:37 +00:00
a107476ca1
Cleaner resolution for the problem mentioned last commit. Fixes mono-namespace charts while assuming multi-namespace charts have the diligence to set `.metadata.namespace` everywhere necessary.
58 lines
1.9 KiB
Nix
58 lines
1.9 KiB
Nix
# All builders used to require a name and namespace, due to my previous
|
|
# (regrettable) decision to use the resultant derivations' names as
|
|
# path signifiers. No longer, because:
|
|
# 1. derivations are collected and directly mapped to target paths, and
|
|
# 2. the output derivation contains symbolic links to each sub-derivation
|
|
# for easy identification.
|
|
# Still, the pnames make derivations easy to identify in the Nix store
|
|
# at a glance, so I've kept them.
|
|
{
|
|
kubelib,
|
|
pkgs,
|
|
}: let
|
|
setNsOnObjects = namespace:
|
|
# Attrset is on LHS in case object sets its own namespace.
|
|
map (obj: pkgs.lib.attrsets.recursiveUpdate {metadata.namespace = namespace;} obj);
|
|
in rec {
|
|
derivation = {
|
|
name,
|
|
namespace,
|
|
src,
|
|
...
|
|
}:
|
|
pkgs.stdenv.mkDerivation {
|
|
pname = "copied-drv-${namespace}-${name}";
|
|
inherit (src) version;
|
|
|
|
inherit src;
|
|
phases = ["installPhase"];
|
|
installPhase = "cp -rv $src $out";
|
|
};
|
|
|
|
helmChart = kubelib.buildHelmChart;
|
|
|
|
# Adapted from github:farcaller/nix-kube-generators ("kubelib").
|
|
yamlStream = {
|
|
name,
|
|
namespace,
|
|
objs,
|
|
...
|
|
}: let
|
|
# Some service modules may include extra resources which, it's (usually)
|
|
# safe to assume, belong to the same namespace. This line removes the need
|
|
# to define the namespace in each extra resource.
|
|
# (Because all objects' metadata is of the ObjectMeta type, non-namespaced
|
|
# objects can have `metadata.namespace` set, too. It will just be ignored
|
|
# at creation time in the Kubernetes cluster.)
|
|
namespacedObjs = setNsOnObjects namespace objs;
|
|
in
|
|
pkgs.stdenv.mkDerivation {
|
|
name = "yaml-stream-${namespace}-${name}";
|
|
|
|
yamlText = pkgs.lib.strings.concatStringsSep "\n---\n" (map builtins.toJSON namespacedObjs);
|
|
passAsFile = "yamlText";
|
|
|
|
phases = ["installPhase"];
|
|
installPhase = "${pkgs.yq-go}/bin/yq -P -M $yamlTextPath > $out";
|
|
};
|
|
}
|