1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

kubecolor: add module

This commit is contained in:
Igor Rzegocki 2024-10-03 15:57:31 +02:00
parent 437ec62009
commit 53c2851281
No known key found for this signature in database
GPG key ID: 031D1340C3ED856C
7 changed files with 149 additions and 0 deletions

View file

@ -1748,6 +1748,13 @@ in {
add `-w` to your assignment of `services.swayidle.extraArgs`. add `-w` to your assignment of `services.swayidle.extraArgs`.
''; '';
} }
{
time = "2024-10-03T12:09:07+00:00";
message = ''
A new module is available: 'programs.kubecolor'.
'';
}
]; ];
}; };
} }

View file

@ -140,6 +140,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,81 @@
{ 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" { };
overrideKubectl = mkOption {
type = types.bool;
default = false;
description = ''
When set to true, it will create an alias for kubectl pointing to kubecolor,
thus making kubecolor default kubectl client.
'';
};
settings = mkOption {
type = yamlFormat.type;
default = { };
description = ''
Configuration written to {file}`$XDG_CONFIG_HOME/kube/color.yaml` (linux)
or {file}`Library/Application Support/kube/color.yaml` (darwin), See
<https://kubecolor.github.io/reference/config/> for supported values.
'';
example = literalExpression ''
kubectl = lib.getExe kubectl
preset = "dark";
paging = "auto";
'';
};
};
config = let
enableXdgConfig = !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.enableNixpkgsReleaseCheck = false;
home.packages = [ cfg.package ];
home.sessionVariables.KUBECOLOR_CONFIG = if enableXdgConfig then
"${config.xdg.configHome}/${configPathSuffix}"
else
"${config.home.homeDirectory}/Library/Application Support/${configPathSuffix}";
xdg.configFile = mkIf enableXdgConfig {
"kube/color.yaml" = mkIf (cfg.settings != { }) {
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
};
};
home.file = mkIf (!enableXdgConfig) {
"Library/Application Support/kube/color.yaml" =
mkIf (cfg.settings != { }) {
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
};
};
home.shellAliases =
lib.mkIf cfg.overrideKubectl { kubectl = lib.getExe cfg.package; };
};
}

View file

@ -96,6 +96,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,4 @@
{
kubecolor-example-config = ./example-config.nix;
kubecolor-empty-config = ./empty-config.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,35 @@
{ 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";
};
settings = {
kubectl = "kubectl";
preset = "dark";
objFreshThreshold = 0;
paging = "auto";
pager = "less";
};
};
nmt.script = ''
assertFileExists 'home-files/${configDir}/kube/color.yaml'
assertFileContent 'home-files/${configDir}/kube/color.yaml' \
${
builtins.toFile "expected.yaml" ''
kubectl: kubectl
objFreshThreshold: 0
pager: less
paging: auto
preset: dark
''
}
'';
}