Skip to content

Commit

Permalink
helm: init module
Browse files Browse the repository at this point in the history
  • Loading branch information
folliehiyuki committed Jan 7, 2025
1 parent 5c43023 commit 6b262d7
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,10 @@
github = "ALameLlama";
githubId = 55490546;
};
folliehiyuki = {
name = "Hoang Nguyen";
email = "[email protected]";
github = "folliehiyuki";
githubId = 67634026;
};
}
9 changes: 9 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,15 @@ in {
speed, features, or native UIs. Ghostty provides all three.
'';
}

{
time = "2025-01-08T06:54:09+00:00";
message = ''
A new module is available: 'programs.helm'.
Helm is a package manager for Kubernetes.
'';
}
];
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ let
./programs/granted.nix
./programs/havoc.nix
./programs/helix.nix
./programs/helm.nix
./programs/hexchat.nix
./programs/himalaya.nix
./programs/home-manager.nix
Expand Down
45 changes: 45 additions & 0 deletions modules/programs/helm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.programs.helm;

enableXdgDir = !pkgs.stdenv.hostPlatform.isDarwin || config.xdg.enable;
in {
meta.maintainers = [ hm.maintainers.folliehiyuki ];

options.programs.helm = {
enable = mkEnableOption "helm";

package = mkPackageOption pkgs "helm" { default = [ "kubernetes-helm" ]; };

plugins = mkOption {
type = with types; attrsOf path;
default = { };
description = ''
Helm plugins to be installed.
Values should be a path containing a top-level `plugin.yaml` file.
Will be linked to {file}`$XDG_DATA_HOME/helm/plugins/<name>/`.
'';
example = literalExpression ''
{
custom = ./custom;
diff = ${pkgs.kubernetes-helmPlugins.helm-diff}/helm-diff;
}
'';
};
};

config = mkIf cfg.enable {
home.packages = [ cfg.package ];

xdg.dataFile = mkIf enableXdgDir (mapAttrs'
(name: value: nameValuePair "helm/plugins/${name}" { source = value; })
cfg.plugins);

home.file = mkIf (!enableXdgDir) (mapAttrs' (name: value:
nameValuePair "Library/helm/plugins/${name}" { source = value; })
cfg.plugins);
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ in import nmtSrc {
./modules/programs/gradle
./modules/programs/granted
./modules/programs/helix
./modules/programs/helm
./modules/programs/himalaya
./modules/programs/htop
./modules/programs/hyfetch
Expand Down
5 changes: 5 additions & 0 deletions tests/modules/programs/helm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
helm-no-plugins = ./helm-no-plugins.nix;
helm-with-plugins = ./helm-with-plugins.nix;
helm-with-plugins-no-xdg = ./helm-with-plugins-no-xdg.nix;
}
14 changes: 14 additions & 0 deletions tests/modules/programs/helm/helm-no-plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ config, ... }:

{
config = {
programs.helm.enable = true;

test.stubs.kubernetes-helm = { };

nmt.script = ''
assertPathNotExists home-files/Library/helm
assertPathNotExists ${config.xdg.dataHome}/helm
'';
};
}
28 changes: 28 additions & 0 deletions tests/modules/programs/helm/helm-with-plugins-no-xdg.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ pkgs, lib, ... }:

{
config = {
xdg.enable = lib.mkForce false;

programs.helm = {
enable = true;

plugins.unittest = "${pkgs.kubernetes-helmPlugins.helm-unittest}/helm-unittest";
};

test.stubs.kubernetes-helm = { };

nmt.script = let
helmPluginsDir = if !pkgs.stdenv.isDarwin then
".local/share/helm/plugins"
else
"Library/helm/plugins";
in ''
assertFileExists home-files/${helmPluginsDir}/unittest/untt
assertFileExists home-files/${helmPluginsDir}/unittest/plugin.yaml
assertFileContains home-files/${helmPluginsDir}/unittest/plugin.yaml \
'command: "$HELM_PLUGIN_DIR/untt"'
'';
};
}
23 changes: 23 additions & 0 deletions tests/modules/programs/helm/helm-with-plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ pkgs, ... }:

{
config = {
xdg.enable = true;

programs.helm = {
enable = true;

plugins.diff = "${pkgs.kubernetes-helmPlugins.helm-diff}/helm-diff";
};

test.stubs.kubernetes-helm = { };

nmt.script = ''
assertFileExists home-files/.local/share/helm/plugins/diff/bin/diff
assertFileExists home-files/.local/share/helm/plugins/diff/plugin.yaml
assertFileContains home-files/.local/share/helm/plugins/diff/plugin.yaml \
'command: "$HELM_PLUGIN_DIR/bin/diff"'
'';
};
}

0 comments on commit 6b262d7

Please sign in to comment.