Merge pull request #288162 from 1nv0k32/kubeswitch-fix-name-and-shell-completion
kubeswitch: fix broken package; add nixos module
This commit is contained in:
commit
715b67f79e
@ -214,6 +214,7 @@
|
||||
./programs/kclock.nix
|
||||
./programs/kdeconnect.nix
|
||||
./programs/lazygit.nix
|
||||
./programs/kubeswitch.nix
|
||||
./programs/less.nix
|
||||
./programs/liboping.nix
|
||||
./programs/light.nix
|
||||
|
56
nixos/modules/programs/kubeswitch.nix
Normal file
56
nixos/modules/programs/kubeswitch.nix
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.programs.kubeswitch;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
programs.kubeswitch = {
|
||||
enable = lib.mkEnableOption (lib.mdDoc "kubeswitch");
|
||||
|
||||
commandName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "kswitch";
|
||||
description = "The name of the command to use";
|
||||
};
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = pkgs.kubeswitch;
|
||||
defaultText = lib.literalExpression "pkgs.kubeswitch";
|
||||
description = "The package to install for kubeswitch";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config =
|
||||
let
|
||||
shell_files = pkgs.stdenv.mkDerivation rec {
|
||||
name = "kubeswitch-shell-files";
|
||||
phases = [ "installPhase" ];
|
||||
installPhase = ''
|
||||
mkdir -p $out/share
|
||||
for shell in bash zsh; do
|
||||
${cfg.package}/bin/switcher init $shell | sed 's/switch(/${cfg.commandName}(/' > $out/share/${cfg.commandName}_init.$shell
|
||||
${cfg.package}/bin/switcher --cmd ${cfg.commandName} completion $shell > $out/share/${cfg.commandName}_completion.$shell
|
||||
done
|
||||
'';
|
||||
};
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
programs.bash.interactiveShellInit = ''
|
||||
source ${shell_files}/share/${cfg.commandName}_init.bash
|
||||
source ${shell_files}/share/${cfg.commandName}_completion.bash
|
||||
'';
|
||||
programs.zsh.interactiveShellInit = ''
|
||||
source ${shell_files}/share/${cfg.commandName}_init.zsh
|
||||
source ${shell_files}/share/${cfg.commandName}_completion.zsh
|
||||
'';
|
||||
};
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
{ lib, buildGoModule, fetchFromGitHub, testers, kubeswitch }:
|
||||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
fetchFromGitHub,
|
||||
testers,
|
||||
kubeswitch,
|
||||
installShellFiles,
|
||||
}:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "kubeswitch";
|
||||
@ -6,9 +13,9 @@ buildGoModule rec {
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "danielfoehrKn";
|
||||
repo = pname;
|
||||
repo = "kubeswitch";
|
||||
rev = version;
|
||||
sha256 = "sha256-zf7o41YYAppRge0EMXgIN8rI5Kco4/n7BJ90b/X6L1M=";
|
||||
hash = "sha256-zf7o41YYAppRge0EMXgIN8rI5Kco4/n7BJ90b/X6L1M=";
|
||||
};
|
||||
|
||||
vendorHash = null;
|
||||
@ -16,25 +23,30 @@ buildGoModule rec {
|
||||
subPackages = [ "cmd/main.go" ];
|
||||
|
||||
ldflags = [
|
||||
"-s" "-w"
|
||||
"-s"
|
||||
"-w"
|
||||
"-X github.com/danielfoehrkn/kubeswitch/cmd/switcher.version=${version}"
|
||||
"-X github.com/danielfoehrkn/kubeswitch/cmd/switcher.buildDate=1970-01-01"
|
||||
|
||||
];
|
||||
|
||||
passthru.tests.version = testers.testVersion {
|
||||
package = kubeswitch;
|
||||
};
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
postInstall = ''
|
||||
mv $out/bin/main $out/bin/switch
|
||||
mv $out/bin/main $out/bin/switcher
|
||||
for shell in bash zsh fish; do
|
||||
$out/bin/switcher --cmd switcher completion $shell > switcher.$shell
|
||||
installShellCompletion --$shell switcher.$shell
|
||||
done
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "The kubectx for operators";
|
||||
license = licenses.asl20;
|
||||
passthru.tests.version = testers.testVersion { package = kubeswitch; };
|
||||
|
||||
meta = {
|
||||
changelog = "https://github.com/danielfoehrKn/kubeswitch/releases/tag/${version}";
|
||||
description = "The kubectx for operators, a drop-in replacement for kubectx";
|
||||
license = lib.licenses.asl20;
|
||||
homepage = "https://github.com/danielfoehrKn/kubeswitch";
|
||||
maintainers = with maintainers; [ bryanasdev000 ];
|
||||
mainProgram = "switch";
|
||||
maintainers = with lib.maintainers; [ bryanasdev000 ];
|
||||
mainProgram = "switcher";
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user