mirror of
https://github.com/nix-community/home-manager
synced 2024-12-11 12:29:47 +01:00
kubecolor: add module
This commit is contained in:
parent
e71e678d18
commit
8632735050
8 changed files with 197 additions and 0 deletions
|
@ -1837,6 +1837,16 @@ in {
|
|||
the same shell inside the new environment.
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2024-12-01T19:34:04+00:00";
|
||||
message = ''
|
||||
A new module is available: 'programs.kubecolor'.
|
||||
|
||||
Kubecolor is a kubectl wrapper used to add colors to your kubectl
|
||||
output.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ let
|
|||
./programs/khard.nix
|
||||
./programs/kitty.nix
|
||||
./programs/kodi.nix
|
||||
./programs/kubecolor.nix
|
||||
./programs/lazygit.nix
|
||||
./programs/ledger.nix
|
||||
./programs/less.nix
|
||||
|
|
87
modules/programs/kubecolor.nix
Normal file
87
modules/programs/kubecolor.nix
Normal file
|
@ -0,0 +1,87 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.programs.kubecolor;
|
||||
yamlFormat = pkgs.formats.yaml { };
|
||||
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
||||
|
||||
in {
|
||||
meta.maintainers = with maintainers; [ ajgon ];
|
||||
|
||||
options.programs.kubecolor = {
|
||||
enable = mkEnableOption "kubecolor - Colorize your kubectl output";
|
||||
|
||||
package = mkPackageOption pkgs "kubecolor" { };
|
||||
|
||||
enableAlias = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
When set to true, it will create an alias for kubectl pointing to
|
||||
kubecolor, thus making kubecolor the default kubectl client.
|
||||
'';
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = yamlFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
kubectl = lib.getExe pkgs.kubectl
|
||||
preset = "dark";
|
||||
paging = "auto";
|
||||
'';
|
||||
description = ''
|
||||
Configuration written to {file}`~/.kube/color.yaml` (Linux)
|
||||
or {file}`Library/Application Support/kube/color.yaml` (Darwin).
|
||||
See <https://kubecolor.github.io/reference/config/> for supported
|
||||
values.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
preferXdgDirectories = config.home.preferXdgDirectories
|
||||
&& (!isDarwin || config.xdg.enable);
|
||||
|
||||
# https://github.com/kubecolor/kubecolor/pull/145
|
||||
configPathSuffix = if cfg.package.pname == "kubecolor"
|
||||
&& lib.strings.toInt (lib.versions.major cfg.package.version) == 0
|
||||
&& lib.strings.toInt (lib.versions.minor cfg.package.version) < 4 then
|
||||
"kube/"
|
||||
else
|
||||
"kube/color.yaml";
|
||||
|
||||
in mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
home.sessionVariables = if preferXdgDirectories then {
|
||||
KUBECOLOR_CONFIG = "${config.xdg.configHome}/${configPathSuffix}";
|
||||
} else if isDarwin then {
|
||||
KUBECOLOR_CONFIG =
|
||||
"${config.home.homeDirectory}/Library/Application Support/${configPathSuffix}";
|
||||
} else
|
||||
{ };
|
||||
|
||||
xdg.configFile = mkIf preferXdgDirectories {
|
||||
"kube/color.yaml" = mkIf (cfg.settings != { }) {
|
||||
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
|
||||
};
|
||||
};
|
||||
|
||||
home.file = mkIf (!preferXdgDirectories) {
|
||||
"Library/Application Support/kube/color.yaml" =
|
||||
mkIf (isDarwin && cfg.settings != { }) {
|
||||
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
|
||||
};
|
||||
".kube/color.yaml" = mkIf (!isDarwin && cfg.settings != { }) {
|
||||
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
|
||||
};
|
||||
};
|
||||
|
||||
home.shellAliases =
|
||||
lib.mkIf cfg.enableAlias { kubectl = lib.getExe cfg.package; };
|
||||
};
|
||||
}
|
|
@ -98,6 +98,7 @@ in import nmtSrc {
|
|||
./modules/programs/khal
|
||||
./modules/programs/khard
|
||||
./modules/programs/kitty
|
||||
./modules/programs/kubecolor
|
||||
./modules/programs/ledger
|
||||
./modules/programs/less
|
||||
./modules/programs/lf
|
||||
|
|
5
tests/modules/programs/kubecolor/default.nix
Normal file
5
tests/modules/programs/kubecolor/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
kubecolor-empty-config = ./empty-config.nix;
|
||||
kubecolor-example-config-default-paths = ./example-config-default-paths.nix;
|
||||
kubecolor-example-config-xdg-paths = ./example-config-xdg-paths.nix;
|
||||
}
|
20
tests/modules/programs/kubecolor/empty-config.nix
Normal file
20
tests/modules/programs/kubecolor/empty-config.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{ pkgs, config, ... }:
|
||||
|
||||
let
|
||||
configDir =
|
||||
if pkgs.stdenv.isDarwin then "Library/Application Support" else ".config";
|
||||
in {
|
||||
programs.kubecolor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage {
|
||||
name = "kubecolor";
|
||||
version = "0.4.0";
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.kubecolor = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertPathNotExists 'home-files/${configDir}/kube/color.yaml'
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
{ pkgs, config, ... }:
|
||||
|
||||
let
|
||||
configDir = if pkgs.stdenv.isDarwin then
|
||||
"Library/Application Support/kube"
|
||||
else
|
||||
".kube";
|
||||
in {
|
||||
programs.kubecolor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage {
|
||||
name = "kubecolor";
|
||||
version = "0.4.0";
|
||||
};
|
||||
settings = {
|
||||
kubectl = "kubectl";
|
||||
preset = "dark";
|
||||
objFreshThreshold = 0;
|
||||
paging = "auto";
|
||||
pager = "less";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists 'home-files/${configDir}/color.yaml'
|
||||
assertFileContent 'home-files/${configDir}/color.yaml' \
|
||||
${
|
||||
builtins.toFile "expected.yaml" ''
|
||||
kubectl: kubectl
|
||||
objFreshThreshold: 0
|
||||
pager: less
|
||||
paging: auto
|
||||
preset: dark
|
||||
''
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
xdg.enable = true;
|
||||
home.preferXdgDirectories = true;
|
||||
|
||||
programs.kubecolor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage {
|
||||
name = "kubecolor";
|
||||
version = "0.4.0";
|
||||
};
|
||||
settings = {
|
||||
kubectl = "kubectl";
|
||||
preset = "dark";
|
||||
objFreshThreshold = 0;
|
||||
paging = "auto";
|
||||
pager = "less";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists 'home-files/.config/kube/color.yaml'
|
||||
assertFileContent 'home-files/.config/kube/color.yaml' \
|
||||
${
|
||||
builtins.toFile "expected.yaml" ''
|
||||
kubectl: kubectl
|
||||
objFreshThreshold: 0
|
||||
pager: less
|
||||
paging: auto
|
||||
preset: dark
|
||||
''
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in a new issue