1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

kubecolor: add module

This commit is contained in:
Igor Rzegocki 2024-10-03 15:57:31 +02:00 committed by Robert Helgesson
parent e71e678d18
commit 8632735050
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
8 changed files with 197 additions and 0 deletions

View file

@ -1837,6 +1837,16 @@ in {
the same shell inside the new environment. 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.
'';
}
]; ];
}; };
} }

View file

@ -143,6 +143,7 @@ let
./programs/khard.nix ./programs/khard.nix
./programs/kitty.nix ./programs/kitty.nix
./programs/kodi.nix ./programs/kodi.nix
./programs/kubecolor.nix
./programs/lazygit.nix ./programs/lazygit.nix
./programs/ledger.nix ./programs/ledger.nix
./programs/less.nix ./programs/less.nix

View 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; };
};
}

View file

@ -98,6 +98,7 @@ in import nmtSrc {
./modules/programs/khal ./modules/programs/khal
./modules/programs/khard ./modules/programs/khard
./modules/programs/kitty ./modules/programs/kitty
./modules/programs/kubecolor
./modules/programs/ledger ./modules/programs/ledger
./modules/programs/less ./modules/programs/less
./modules/programs/lf ./modules/programs/lf

View 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;
}

View 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'
'';
}

View file

@ -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
''
}
'';
}

View file

@ -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
''
}
'';
}