mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
kubeswitch: add module
Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr> Co-authored-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
92db5be8e1
commit
af8a884164
10 changed files with 220 additions and 0 deletions
1
.github/labeler.yml
vendored
1
.github/labeler.yml
vendored
|
|
@ -207,6 +207,7 @@
|
|||
- modules/programs/java.nix
|
||||
- modules/programs/jetbrains-remote.nix
|
||||
- modules/programs/kubecolor.nix
|
||||
- modules/programs/kubeswitch.nix
|
||||
- modules/programs/lazydocker.nix
|
||||
- modules/programs/matplotlib.nix
|
||||
- modules/programs/mercurial.nix
|
||||
|
|
|
|||
10
modules/misc/news/2025/06/2025-06-13_18-14-02.nix
Normal file
10
modules/misc/news/2025/06/2025-06-13_18-14-02.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
time = "2025-06-13T16:14:02+00:00";
|
||||
condition = true;
|
||||
message = ''
|
||||
A new module is available: 'programs.kubeswitch'.
|
||||
|
||||
The kubectx for operators.
|
||||
kubeswitch (lazy: switch) is the single pane of glass for all of your kubeconfig files.
|
||||
'';
|
||||
}
|
||||
115
modules/programs/kubeswitch.nix
Normal file
115
modules/programs/kubeswitch.nix
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.programs.kubeswitch;
|
||||
|
||||
yamlFormat = pkgs.formats.yaml { };
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ lib.hm.maintainers.m0nsterrr ];
|
||||
|
||||
options.programs.kubeswitch = {
|
||||
enable = lib.mkEnableOption "the kubectx for operators";
|
||||
|
||||
commandName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "kswitch";
|
||||
description = "The name of the command to use";
|
||||
};
|
||||
|
||||
package = lib.mkPackageOption pkgs "kubeswitch" { };
|
||||
|
||||
enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
||||
|
||||
enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };
|
||||
|
||||
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = yamlFormat.type;
|
||||
default = { };
|
||||
example = {
|
||||
kind = "SwitchConfig";
|
||||
kubeconfigName = "*.myconfig";
|
||||
kubeconfigStores = [
|
||||
{
|
||||
kind = "filesystem";
|
||||
kubeconfigName = "*.myconfig";
|
||||
paths = [
|
||||
"~/.kube/my-other-kubeconfigs/"
|
||||
];
|
||||
}
|
||||
];
|
||||
version = "v1alpha1";
|
||||
};
|
||||
description = ''
|
||||
Configuration written to
|
||||
{file}`~/.kube/switch-config.yaml`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home = {
|
||||
packages = [ cfg.package ];
|
||||
|
||||
file.".kube/switch-config.yaml" = lib.mkIf (cfg.settings != { }) {
|
||||
source = yamlFormat.generate "kubeswitch-settings" cfg.settings;
|
||||
};
|
||||
};
|
||||
|
||||
programs =
|
||||
let
|
||||
generateKubeswitchShellFiles =
|
||||
shell:
|
||||
pkgs.runCommand "kubeswitch-${cfg.commandName}-shell-files-for-${shell}"
|
||||
{
|
||||
nativeBuildInputs = [ cfg.package ];
|
||||
}
|
||||
''
|
||||
mkdir -p $out/share
|
||||
switcher init "${shell}" | sed "s/switch(/${cfg.commandName}(/" > "$out/share/${cfg.commandName}_init.${shell}"
|
||||
switcher --cmd "${cfg.commandName}" completion "${shell}" > "$out/share/${cfg.commandName}_completion.${shell}"
|
||||
'';
|
||||
in
|
||||
{
|
||||
bash.initExtra =
|
||||
let
|
||||
kubeswitchBashFiles = generateKubeswitchShellFiles "bash";
|
||||
in
|
||||
lib.mkIf cfg.enableBashIntegration ''
|
||||
source ${kubeswitchBashFiles}/share/${cfg.commandName}_init.bash
|
||||
source ${kubeswitchBashFiles}/share/${cfg.commandName}_completion.bash
|
||||
'';
|
||||
|
||||
fish.interactiveShellInit =
|
||||
let
|
||||
shell_files =
|
||||
pkgs.runCommand "kubeswitch-${cfg.commandName}-shell-files-for-fish"
|
||||
{ buildInputs = [ cfg.package ]; }
|
||||
''
|
||||
mkdir -p $out/share
|
||||
switcher init fish | sed "s/kubeswitch/${cfg.commandName}/" > $out/share/${cfg.commandName}_init.fish
|
||||
switcher --cmd ${cfg.commandName} completion fish > $out/share/${cfg.commandName}_completion.fish
|
||||
'';
|
||||
in
|
||||
lib.mkIf cfg.enableFishIntegration ''
|
||||
source ${shell_files}/share/${cfg.commandName}_init.fish
|
||||
source ${shell_files}/share/${cfg.commandName}_completion.fish
|
||||
'';
|
||||
|
||||
zsh.initContent =
|
||||
let
|
||||
kubeswitchZshFiles = generateKubeswitchShellFiles "zsh";
|
||||
in
|
||||
lib.mkIf cfg.enableZshIntegration ''
|
||||
source ${kubeswitchZshFiles}/share/${cfg.commandName}_init.zsh
|
||||
source ${kubeswitchZshFiles}/share/${cfg.commandName}_completion.zsh
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -77,6 +77,7 @@ let
|
|||
"khard"
|
||||
"kitty"
|
||||
"kubecolor"
|
||||
"kubeswitch"
|
||||
"lapce"
|
||||
"lazydocker"
|
||||
"lazygit"
|
||||
|
|
|
|||
14
tests/modules/programs/kubeswitch/bash.nix
Normal file
14
tests/modules/programs/kubeswitch/bash.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
programs = {
|
||||
kubeswitch.enable = true;
|
||||
bash.enable = true;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.bashrc
|
||||
assertFileRegex home-files/.bashrc \
|
||||
'^source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-bash/share/kswitch_init.bash$'
|
||||
assertFileRegex home-files/.bashrc \
|
||||
'^source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-bash/share/kswitch_completion.bash$'
|
||||
'';
|
||||
}
|
||||
7
tests/modules/programs/kubeswitch/default.nix
Normal file
7
tests/modules/programs/kubeswitch/default.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
kubeswitch-bash = ./bash.nix;
|
||||
kubeswitch-empty-settings = ./empty-settings.nix;
|
||||
kubeswitch-example-settings = ./example-settings.nix;
|
||||
kubeswitch-fish = ./fish.nix;
|
||||
kubeswitch-zsh = ./zsh.nix;
|
||||
}
|
||||
7
tests/modules/programs/kubeswitch/empty-settings.nix
Normal file
7
tests/modules/programs/kubeswitch/empty-settings.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
programs.kubeswitch.enable = true;
|
||||
|
||||
nmt.script = ''
|
||||
assertPathNotExists home-files/.kube/switch-config.yaml
|
||||
'';
|
||||
}
|
||||
35
tests/modules/programs/kubeswitch/example-settings.nix
Normal file
35
tests/modules/programs/kubeswitch/example-settings.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
programs.kubeswitch = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
kind = "SwitchConfig";
|
||||
version = "v1alpha1";
|
||||
kubeconfigName = "*.myconfig";
|
||||
kubeconfigStores = [
|
||||
{
|
||||
kind = "filesystem";
|
||||
kubeconfigName = "*.myconfig";
|
||||
paths = [
|
||||
"~/.kube/my-other-kubeconfigs/"
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContent \
|
||||
home-files/.kube/switch-config.yaml \
|
||||
${builtins.toFile "example-settings-expected.yaml" ''
|
||||
kind: SwitchConfig
|
||||
kubeconfigName: '*.myconfig'
|
||||
kubeconfigStores:
|
||||
- kind: filesystem
|
||||
kubeconfigName: '*.myconfig'
|
||||
paths:
|
||||
- ~/.kube/my-other-kubeconfigs/
|
||||
version: v1alpha1
|
||||
''}
|
||||
'';
|
||||
}
|
||||
16
tests/modules/programs/kubeswitch/fish.nix
Normal file
16
tests/modules/programs/kubeswitch/fish.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
programs = {
|
||||
kubeswitch.enable = true;
|
||||
fish.enable = true;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/fish/config.fish
|
||||
assertFileRegex home-files/.config/fish/config.fish \
|
||||
'^\s*source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-fish/share/kswitch_init.fish$'
|
||||
assertFileRegex home-files/.config/fish/config.fish \
|
||||
'^\s*source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-fish/share/kswitch_completion.fish$'
|
||||
'';
|
||||
}
|
||||
14
tests/modules/programs/kubeswitch/zsh.nix
Normal file
14
tests/modules/programs/kubeswitch/zsh.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
programs = {
|
||||
kubeswitch.enable = true;
|
||||
zsh.enable = true;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.zshrc
|
||||
assertFileRegex home-files/.zshrc \
|
||||
'^source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-zsh/share/kswitch_init.zsh$'
|
||||
assertFileRegex home-files/.zshrc \
|
||||
'^source /nix/store/[0-9a-z]*-kubeswitch-kswitch-shell-files-for-zsh/share/kswitch_completion.zsh$'
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue