k9s: configuration files in Darwin without XDG

Support alternate configuration files for k9s in darwin where XDG is
not mandated and k9s expects configuration files in
`~/Library/Application Support/k9s/`.
This commit is contained in:
Jose Plana 2024-04-10 13:34:46 +02:00 committed by Robert Helgesson
parent 76a1650c45
commit 9f32c66a51
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
3 changed files with 85 additions and 31 deletions

View file

@ -6,6 +6,7 @@ let
cfg = config.programs.k9s;
yamlFormat = pkgs.formats.yaml { };
inherit (pkgs.stdenv.hostPlatform) isDarwin;
in {
meta.maintainers = with maintainers; [
@ -33,7 +34,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yaml`. See
Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yaml` (linux)
or {file}`Library/Application Support/k9s/config.yaml` (darwin), See
<https://k9scli.io/topics/config/> for supported values.
'';
example = literalExpression ''
@ -47,7 +49,8 @@ in {
type = types.attrsOf yamlFormat.type;
default = { };
description = ''
Skin files written to {file}`$XDG_CONFIG_HOME/k9s/skins/`. See
Skin files written to {file}`$XDG_CONFIG_HOME/k9s/skins/` (linux)
or {file}`Library/Application Support/k9s/skins/` (darwin). See
<https://k9scli.io/topics/skins/> for supported values.
'';
example = literalExpression ''
@ -65,7 +68,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yaml`. See
Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yaml` (linux)
or {file}`Library/Application Support/k9s/aliases.yaml` (darwin). See
<https://k9scli.io/topics/aliases/> for supported values.
'';
example = literalExpression ''
@ -80,7 +84,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkeys.yaml`. See
Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkeys.yaml` (linux)
or {file}`Library/Application Support/k9s/hotkeys.yaml` (darwin). See
<https://k9scli.io/topics/hotkeys/> for supported values.
'';
example = literalExpression ''
@ -101,7 +106,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugins.yaml`. See
Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugins.yaml (linux)`
or {file}`Library/Application Support/k9s/plugins.yaml` (darwin). See
<https://k9scli.io/topics/plugins/> for supported values.
'';
example = literalExpression ''
@ -132,7 +138,9 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Resource column views written to {file}`$XDG_CONFIG_HOME/k9s/views.yaml`.
Resource column views written to
{file}`$XDG_CONFIG_HOME/k9s/views.yaml (linux)`
or {file}`Library/Application Support/k9s/views.yaml` (darwin).
See <https://k9scli.io/topics/columns/> for supported values.
'';
example = literalExpression ''
@ -162,13 +170,19 @@ in {
{ };
skinFiles = mapAttrs' (name: value:
nameValuePair "k9s/skins/${name}.yaml" {
source = yamlFormat.generate "k9s-skin-${name}.yaml" value;
}) cfg.skins;
nameValuePair (if !(isDarwin && !config.xdg.enable) then
"k9s/skins/${name}.yaml"
else
"Library/Application Support/k9s/skins/${name}.yaml") {
source = yamlFormat.generate "k9s-skin-${name}.yaml" value;
}) cfg.skins;
enableXdgConfig = !isDarwin || config.xdg.enable;
in mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile = {
xdg.configFile = mkIf enableXdgConfig ({
"k9s/config.yaml" = mkIf (cfg.settings != { }) {
source = yamlFormat.generate "k9s-config"
(lib.recursiveUpdate skinSetting cfg.settings);
@ -189,6 +203,33 @@ in {
"k9s/views.yaml" = mkIf (cfg.views != { }) {
source = yamlFormat.generate "k9s-views" cfg.views;
};
} // skinFiles;
} // skinFiles);
home.file = mkIf (!enableXdgConfig) ({
"Library/Application Support/k9s/config.yaml" =
mkIf (cfg.settings != { }) {
source = yamlFormat.generate "k9s-config"
(lib.recursiveUpdate skinSetting cfg.settings);
};
"Library/Application Support/k9s/aliases.yaml" =
mkIf (cfg.aliases != { }) {
source = yamlFormat.generate "k9s-aliases" cfg.aliases;
};
"Library/Application Support/k9s/hotkeys.yaml" =
mkIf (cfg.hotkey != { }) {
source = yamlFormat.generate "k9s-hotkey" cfg.hotkey;
};
"Library/Application Support/k9s/plugins.yaml" =
mkIf (cfg.plugin != { }) {
source = yamlFormat.generate "k9s-plugin" cfg.plugin;
};
"Library/Application Support/k9s/views.yaml" = mkIf (cfg.views != { }) {
source = yamlFormat.generate "k9s-views" cfg.views;
};
} // skinFiles);
};
}