From 78894bd3b159687e30f59274ea86a255f112cd74 Mon Sep 17 00:00:00 2001 From: Patrick MARIE Date: Sun, 24 Mar 2024 09:33:05 +0100 Subject: [PATCH] Adding an extend example (helm+oci) --- helm-poc/nix/helm.nix | 11 +++++++---- poc-helm-oci/default.nix | 14 ++++++++++++++ poc-helm-oci/packages/manifests/default.nix | 20 ++++++++++++++++++++ poc-helm-oci/packages/oci-image/default.nix | 18 ++++++++++++++++++ poc-helm-oci/values/cert-manager.yaml | 1 + 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 poc-helm-oci/default.nix create mode 100644 poc-helm-oci/packages/manifests/default.nix create mode 100644 poc-helm-oci/packages/oci-image/default.nix create mode 100644 poc-helm-oci/values/cert-manager.yaml diff --git a/helm-poc/nix/helm.nix b/helm-poc/nix/helm.nix index e2dbd29..83cb696 100644 --- a/helm-poc/nix/helm.nix +++ b/helm-poc/nix/helm.nix @@ -10,9 +10,10 @@ let url, hash ? lib.fakeSha25, namespace ? "", - patches ? [] + patches ? [], + values ? "" }: - pkgs.stdenv.mkDerivation { + pkgs.stdenv.mkDerivation rec { inherit name patches; src = pkgs.fetchurl { @@ -25,12 +26,14 @@ let "build" ]; - namespace = if namespace != "" then "--namespace ${namespace}" else ""; + namespaceOpts = if namespace != "" then "--namespace ${namespace}" else ""; + valuesOpts = if values != "" then "--values ${values}" else ""; build = '' mkdir -p $out ${helm} template \ - --namespace ${namespace} \ + ${namespaceOpts} \ + ${valuesOpts} \ ${name} ./ > $out/${name}-${version}.yaml ${helm} version > $out/VERSION ''; diff --git a/poc-helm-oci/default.nix b/poc-helm-oci/default.nix new file mode 100644 index 0000000..ad337c7 --- /dev/null +++ b/poc-helm-oci/default.nix @@ -0,0 +1,14 @@ +{ + pkgs ? import {} +, lib ? pkgs.lib +, extend ? pkgs.extend +}: +let + extendedAttrs = extend (final: prev: { + localOutputs = { + manifests = final.callPackage ./packages/manifests {}; + oci-image = final.callPackage ./packages/oci-image {}; + }; + }); +in + extendedAttrs.localOutputs \ No newline at end of file diff --git a/poc-helm-oci/packages/manifests/default.nix b/poc-helm-oci/packages/manifests/default.nix new file mode 100644 index 0000000..3eda086 --- /dev/null +++ b/poc-helm-oci/packages/manifests/default.nix @@ -0,0 +1,20 @@ +{ + pkgs +, lib +, helmnix ? import ../../../helm-poc/nix/helm.nix {} +}: +helmnix.mkHelm rec { + name = "cert-manager"; + version = "v1.14.4"; + url = "https://charts.jetstack.io/charts/${name}-${version}.tgz"; + hash = "sha256-V3X9vBiB1uUQ33bTh1OvVLhr0Uyqjtso/bt5UnBC3t4="; + values = ./../../values/cert-manager.yaml; +} + +#pkgs.dockerTools.streamLayeredImage { +# name = "oci-image"; +# includeStorePaths = false; +# fakeRootCommands = '' +# cp -Lr ${localOutputs.charts}/* . +# rm -fr nix +# ''; diff --git a/poc-helm-oci/packages/oci-image/default.nix b/poc-helm-oci/packages/oci-image/default.nix new file mode 100644 index 0000000..e9960c0 --- /dev/null +++ b/poc-helm-oci/packages/oci-image/default.nix @@ -0,0 +1,18 @@ +{ + pkgs, + lib, + localOutputs, +}: +pkgs.dockerTools.streamLayeredImage { + name = "oci-image"; + includeStorePaths = false; + fakeRootCommands = '' + cp -Lr ${localOutputs.manifests}/* . + rm -fr nix + ''; + +# config.Entrypoint = ["${lib.getExe localOutputs.binaries.simple-package}"]; +# contents = [ +# pkgs.hello +# ]; +} diff --git a/poc-helm-oci/values/cert-manager.yaml b/poc-helm-oci/values/cert-manager.yaml new file mode 100644 index 0000000..ccb5cb1 --- /dev/null +++ b/poc-helm-oci/values/cert-manager.yaml @@ -0,0 +1 @@ +namespace: testaroo