kubecolor: clean up the handling of config path

This commit is contained in:
Hoang Nguyen 2026-01-12 21:55:26 +07:00 committed by Austin Horstman
parent 94597e670f
commit 1dc235b2fb
4 changed files with 15 additions and 29 deletions

View file

@ -49,20 +49,9 @@ in
config =
let
preferXdgDirectories =
config.home.preferXdgDirectories && (!pkgs.stdenv.hostPlatform.isDarwin || config.xdg.enable);
configDir =
if preferXdgDirectories then
"${config.xdg.configHome}/kube"
else if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/kube"
else
".kube";
# https://github.com/kubecolor/kubecolor/pull/145
configPathSuffix = lib.optionalString (
cfg.package.pname == "kubecolor" && lib.versionOlder (lib.getVersion cfg.package) "0.4"
) "color.yaml";
preferXdgDirectories = config.home.preferXdgDirectories && config.xdg.enable;
configFile =
if preferXdgDirectories then "${config.xdg.configHome}/kubecolor.yaml" else ".kube/color.yaml";
in
mkIf cfg.enable {
@ -74,9 +63,11 @@ in
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
home.sessionVariables.KUBECOLOR_CONFIG = "${configDir}/${configPathSuffix}";
home.sessionVariables = lib.mkIf preferXdgDirectories {
KUBECOLOR_CONFIG = configFile;
};
home.file."${configDir}/color.yaml" = mkIf (cfg.settings != { }) {
home.file.${configFile} = mkIf (cfg.settings != { }) {
source = yamlFormat.generate "kubecolor-settings" cfg.settings;
};

View file

@ -1,8 +1,5 @@
{ pkgs, config, ... }:
{ config, ... }:
let
configDir = if pkgs.stdenv.isDarwin then "Library/Application Support" else ".config";
in
{
programs.kubecolor = {
enable = true;
@ -13,6 +10,7 @@ in
};
nmt.script = ''
assertPathNotExists 'home-files/${configDir}/kube/color.yaml'
assertPathNotExists 'home-files/.kube/color.yaml'
assertPathNotExists 'home-files/.config/kubecolor.yaml'
'';
}

View file

@ -1,8 +1,5 @@
{ pkgs, config, ... }:
{ config, ... }:
let
configDir = if pkgs.stdenv.isDarwin then "Library/Application Support/kube" else ".kube";
in
{
programs.kubecolor = {
enable = true;
@ -20,8 +17,8 @@ in
};
nmt.script = ''
assertFileExists 'home-files/${configDir}/color.yaml'
assertFileContent 'home-files/${configDir}/color.yaml' \
assertFileExists 'home-files/.kube/color.yaml'
assertFileContent 'home-files/.kube/color.yaml' \
${builtins.toFile "expected.yaml" ''
kubectl: kubectl
objFreshThreshold: 0

View file

@ -20,8 +20,8 @@
};
nmt.script = ''
assertFileExists 'home-files/.config/kube/color.yaml'
assertFileContent 'home-files/.config/kube/color.yaml' \
assertFileExists 'home-files/.config/kubecolor.yaml'
assertFileContent 'home-files/.config/kubecolor.yaml' \
${builtins.toFile "expected.yaml" ''
kubectl: kubectl
objFreshThreshold: 0