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:
parent
437ec62009
commit
53c2851281
7 changed files with 149 additions and 0 deletions
|
@ -1748,6 +1748,13 @@ in {
|
|||
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'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ let
|
|||
./programs/khard.nix
|
||||
./programs/kitty.nix
|
||||
./programs/kodi.nix
|
||||
./programs/kubecolor.nix
|
||||
./programs/lazygit.nix
|
||||
./programs/ledger.nix
|
||||
./programs/less.nix
|
||||
|
|
81
modules/programs/kubecolor.nix
Normal file
81
modules/programs/kubecolor.nix
Normal 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; };
|
||||
};
|
||||
}
|
|
@ -96,6 +96,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
|
||||
|
|
4
tests/modules/programs/kubecolor/default.nix
Normal file
4
tests/modules/programs/kubecolor/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
kubecolor-example-config = ./example-config.nix;
|
||||
kubecolor-empty-config = ./empty-config.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'
|
||||
'';
|
||||
}
|
35
tests/modules/programs/kubecolor/example-config.nix
Normal file
35
tests/modules/programs/kubecolor/example-config.nix
Normal 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
|
||||
''
|
||||
}
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue