nixos/k3s: support fetching helm charts from OCI registries (#404328)

Changed files
+19 -7
nixos
modules
services
cluster
+19 -7
nixos/modules/services/cluster/k3s/default.nix
···
)
);
-
# Replace characters that are problematic in file names
+
# Replace prefixes and characters that are problematic in file names
cleanHelmChartName =
+
name:
+
let
+
woPrefix = lib.removePrefix "https://" (lib.removePrefix "oci://" name);
+
in
lib.replaceStrings
[
"/"
···
[
"-"
"-"
-
];
+
]
+
woPrefix;
# Fetch a Helm chart from a public registry. This only supports a basic Helm pull.
fetchHelm =
···
version,
hash ? lib.fakeHash,
}:
-
pkgs.runCommand (cleanHelmChartName "${lib.removePrefix "https://" repo}-${name}-${version}.tgz")
+
let
+
isOci = lib.hasPrefix "oci://" repo;
+
pullCmd = if isOci then repo else "--repo ${repo} ${name}";
+
name' = if isOci then "${repo}-${version}" else "${repo}-${name}-${version}";
+
in
+
pkgs.runCommand (cleanHelmChartName "${name'}.tgz")
{
inherit (lib.fetchers.normalizeHash { } { inherit hash; }) outputHash outputHashAlgo;
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
···
];
}
''
-
export HOME="$PWD"
-
helm repo add repository ${repo}
-
helm pull repository/${name} --version ${version}
+
helm pull ${pullCmd} --version ${version}
mv ./*.tgz $out
'';
···
};
};
};
-
+
nginx = {
+
repo = "oci://registry-1.docker.io/bitnamicharts/nginx";
+
version = "20.0.0";
+
hash = "sha256-sy+tzB+i9jIl/tqOMzzuhVhTU4EZVsoSBtPznxF/36c=";
+
};
custom-chart = {
package = ../charts/my-chart.tgz;
values = ../values/my-values.yaml;