Helm Plugins on NixOS

I ran into an unexpected issue and fix trying to use kubernetes-helm, helmfile, and kubernetes-helmPlugins.helm-diff on NixOS. The fix seemed non-trivial, so I’m leaving this here.

Having added the following to my configuration.nix:

  environment.systemPackages = with pkgs; [
    kubectl
    kubernetes-helm
    helmfile
    kubernetes-helmPlugins.helm-diff
  ];

…I was getting this nasty error:

$ helmfile apply
Adding repo prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories

Comparing release=prometheus-rel-2, chart=prometheus-community/prometheus
in ./helmfile.yaml: in .helmfiles[0]: in prometheus/helmfile.yaml: command "/run/current-system/sw/bin/helm" exited with non-zero status:

PATH:
  /run/current-system/sw/bin/helm

ARGS:
  0: helm (4 bytes)
  1: diff (4 bytes)
  2: upgrade (7 bytes)
  3: --allow-unreleased (18 bytes)
  4: prometheus-rel-2 (16 bytes)
  5: prometheus-community/prometheus (31 bytes)
  6: --namespace (11 bytes)
  7: prometheus (10 bytes)
  8: --set (5 bytes)
  9: *** STRIP *** (13 bytes)
  10: --detailed-exitcode (19 bytes)
  11: --color (7 bytes)
  12: --reset-values (14 bytes)

ERROR:
  exit status 1

EXIT STATUS
  1

STDERR:
  Error: unknown command "diff" for "helm"
  Run 'helm --help' for usage.

COMBINED OUTPUT:
  Error: unknown command "diff" for "helm"
  Run 'helm --help' for usage.

For whatever reason, this is the right way to do it:

  environment.systemPackages = with pkgs; [
    kubectl
    kubernetes-helm
    helmfile
    (pkgs.wrapHelm pkgs.kubernetes-helm { plugins = [ pkgs.kubernetes-helmPlugins.helm-diff ]; })
  ];
$ sudo nixos-rebuild switch
...
$ helmfile apply
Adding repo prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories

Comparing release=prometheus-rel-2, chart=prometheus-community/prometheus

Nathan Hensel

on caving, mountaineering, networking, computing, electronics


2024-01-17