diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 9fe03dcf..f4506843 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -159,6 +159,12 @@ github = "loicreynier"; githubId = 88983487; }; + LucasWagler = { + name = "Lucas Wagler"; + email = "lucas@wagler.dev"; + github = "LucasWagler"; + githubId = 32136449; + }; matrss = { name = "Matthias Riße"; email = "matrss@users.noreply.github.com"; diff --git a/modules/programs/k9s.nix b/modules/programs/k9s.nix index 43de8f79..900e129e 100644 --- a/modules/programs/k9s.nix +++ b/modules/programs/k9s.nix @@ -8,7 +8,20 @@ let yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = with maintainers; [ katexochen liyangau ]; + meta.maintainers = with maintainers; [ + katexochen + liyangau + hm.maintainers.LucasWagler + ]; + + imports = [ + (mkRenamedOptionModule [ "programs" "k9s" "skin" ] [ + "programs" + "k9s" + "skins" + "skin" + ]) + ]; options.programs.k9s = { enable = @@ -20,7 +33,7 @@ in { type = yamlFormat.type; default = { }; description = '' - Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yml`. See + Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yaml`. See for supported values. ''; example = literalExpression '' @@ -30,17 +43,19 @@ in { ''; }; - skin = mkOption { - type = yamlFormat.type; + skins = mkOption { + type = types.attrsOf yamlFormat.type; default = { }; description = '' - Skin written to {file}`$XDG_CONFIG_HOME/k9s/skin.yml`. See + Skin files written to {file}`$XDG_CONFIG_HOME/k9s/skins/`. See for supported values. ''; example = literalExpression '' - k9s = { - body = { - fgColor = "dodgerblue"; + my_blue_skin = { + k9s = { + body = { + fgColor = "dodgerblue"; + }; }; }; ''; @@ -50,7 +65,7 @@ in { type = yamlFormat.type; default = { }; description = '' - Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yml`. See + Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yaml`. See for supported values. ''; example = literalExpression '' @@ -65,7 +80,7 @@ in { type = yamlFormat.type; default = { }; description = '' - Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkey.yml`. See + Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkey.yaml`. See for supported values. ''; example = literalExpression '' @@ -86,7 +101,7 @@ in { type = yamlFormat.type; default = { }; description = '' - Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugin.yml`. See + Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugin.yaml`. See for supported values. ''; example = literalExpression '' @@ -117,7 +132,7 @@ in { type = yamlFormat.type; default = { }; description = '' - Resource column views written to {file}`$XDG_CONFIG_HOME/k9s/views.yml`. + Resource column views written to {file}`$XDG_CONFIG_HOME/k9s/views.yaml`. See for supported values. ''; example = literalExpression '' @@ -140,31 +155,40 @@ in { }; }; - config = mkIf cfg.enable { + config = let + skinSetting = if (!(cfg.settings ? k9s.ui.skin) && cfg.skins != { }) then { + k9s.ui.skin = "${builtins.elemAt (builtins.attrNames cfg.skins) 0}"; + } else + { }; + + skinFiles = mapAttrs' (name: value: + nameValuePair "k9s/skins/${name}.yaml" { + source = yamlFormat.generate "k9s-skin-${name}.yaml" value; + }) cfg.skins; + in mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."k9s/config.yml" = mkIf (cfg.settings != { }) { - source = yamlFormat.generate "k9s-config" cfg.settings; - }; + xdg.configFile = { + "k9s/config.yaml" = mkIf (cfg.settings != { }) { + source = yamlFormat.generate "k9s-config" + (lib.recursiveUpdate skinSetting cfg.settings); + }; - xdg.configFile."k9s/skin.yml" = mkIf (cfg.skin != { }) { - source = yamlFormat.generate "k9s-skin" cfg.skin; - }; + "k9s/aliases.yaml" = mkIf (cfg.aliases != { }) { + source = yamlFormat.generate "k9s-aliases" cfg.aliases; + }; - xdg.configFile."k9s/aliases.yml" = mkIf (cfg.aliases != { }) { - source = yamlFormat.generate "k9s-aliases" cfg.aliases; - }; + "k9s/hotkey.yaml" = mkIf (cfg.hotkey != { }) { + source = yamlFormat.generate "k9s-hotkey" cfg.hotkey; + }; - xdg.configFile."k9s/hotkey.yml" = mkIf (cfg.hotkey != { }) { - source = yamlFormat.generate "k9s-hotkey" cfg.hotkey; - }; + "k9s/plugin.yaml" = mkIf (cfg.plugin != { }) { + source = yamlFormat.generate "k9s-plugin" cfg.plugin; + }; - xdg.configFile."k9s/plugin.yml" = mkIf (cfg.plugin != { }) { - source = yamlFormat.generate "k9s-plugin" cfg.plugin; - }; - - xdg.configFile."k9s/views.yml" = mkIf (cfg.views != { }) { - source = yamlFormat.generate "k9s-views" cfg.views; - }; + "k9s/views.yaml" = mkIf (cfg.views != { }) { + source = yamlFormat.generate "k9s-views" cfg.views; + }; + } // skinFiles; }; } diff --git a/tests/modules/programs/k9s/default.nix b/tests/modules/programs/k9s/default.nix index 58d9f32f..6f5b1ba2 100644 --- a/tests/modules/programs/k9s/default.nix +++ b/tests/modules/programs/k9s/default.nix @@ -1,4 +1,6 @@ { k9s-example-settings = ./example-settings.nix; k9s-empty-settings = ./empty-settings.nix; + k9s-deprecated-options = ./deprecated-options.nix; + k9s-partial-skin-settings = ./partial-skin-settings.nix; } diff --git a/tests/modules/programs/k9s/deprecated-options.nix b/tests/modules/programs/k9s/deprecated-options.nix new file mode 100644 index 00000000..57527252 --- /dev/null +++ b/tests/modules/programs/k9s/deprecated-options.nix @@ -0,0 +1,31 @@ +{ config, lib, options, ... }: { + programs.k9s = { + enable = true; + skin = { + k9s = { + body = { + fgColor = "dodgerblue"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "lightskyblue"; + sectionColor = "steelblue"; + }; + }; + }; + }; + + test.asserts.warnings.enable = true; + test.asserts.warnings.expected = [ + "The option `programs.k9s.skin' defined in ${ + lib.showFiles options.programs.k9s.skin.files + } has been renamed to `programs.k9s.skins.skin'." + ]; + nmt.script = '' + assertFileExists home-files/.config/k9s/skins/skin.yaml + assertFileContent \ + home-files/.config/k9s/skins/skin.yaml \ + ${./example-skin-expected.yaml} + ''; +} diff --git a/tests/modules/programs/k9s/example-aliases-expected.yml b/tests/modules/programs/k9s/example-aliases-expected.yaml similarity index 100% rename from tests/modules/programs/k9s/example-aliases-expected.yml rename to tests/modules/programs/k9s/example-aliases-expected.yaml diff --git a/tests/modules/programs/k9s/example-config-expected.yml b/tests/modules/programs/k9s/example-config-expected.yaml similarity index 76% rename from tests/modules/programs/k9s/example-config-expected.yml rename to tests/modules/programs/k9s/example-config-expected.yaml index 019ee7a7..5f4c43ff 100644 --- a/tests/modules/programs/k9s/example-config-expected.yml +++ b/tests/modules/programs/k9s/example-config-expected.yaml @@ -3,3 +3,5 @@ k9s: headless: false maxConnRetry: 5 refreshRate: 2 + ui: + skin: default diff --git a/tests/modules/programs/k9s/example-hotkey-expected.yml b/tests/modules/programs/k9s/example-hotkey-expected.yaml similarity index 100% rename from tests/modules/programs/k9s/example-hotkey-expected.yml rename to tests/modules/programs/k9s/example-hotkey-expected.yaml diff --git a/tests/modules/programs/k9s/example-plugin-expected.yml b/tests/modules/programs/k9s/example-plugin-expected.yaml similarity index 100% rename from tests/modules/programs/k9s/example-plugin-expected.yml rename to tests/modules/programs/k9s/example-plugin-expected.yaml diff --git a/tests/modules/programs/k9s/example-settings.nix b/tests/modules/programs/k9s/example-settings.nix index 3c935aa6..7816a050 100644 --- a/tests/modules/programs/k9s/example-settings.nix +++ b/tests/modules/programs/k9s/example-settings.nix @@ -11,6 +11,7 @@ maxConnRetry = 5; enableMouse = true; headless = false; + ui.skin = "default"; }; }; hotkey = { @@ -22,16 +23,31 @@ }; }; }; - skin = { - k9s = { - body = { - fgColor = "dodgerblue"; - bgColor = "#ffffff"; - logoColor = "#0000ff"; + skins = { + "default" = { + k9s = { + body = { + fgColor = "dodgerblue"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "lightskyblue"; + sectionColor = "steelblue"; + }; }; - info = { - fgColor = "lightskyblue"; - sectionColor = "steelblue"; + }; + "alt-skin" = { + k9s = { + body = { + fgColor = "orangered"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "red"; + sectionColor = "mediumvioletred"; + }; }; }; }; @@ -61,29 +77,33 @@ }; nmt.script = '' - assertFileExists home-files/.config/k9s/config.yml + assertFileExists home-files/.config/k9s/config.yaml assertFileContent \ - home-files/.config/k9s/config.yml \ - ${./example-config-expected.yml} - assertFileExists home-files/.config/k9s/skin.yml + home-files/.config/k9s/config.yaml \ + ${./example-config-expected.yaml} + assertFileExists home-files/.config/k9s/skins/default.yaml assertFileContent \ - home-files/.config/k9s/skin.yml \ - ${./example-skin-expected.yml} - assertFileExists home-files/.config/k9s/hotkey.yml + home-files/.config/k9s/skins/default.yaml \ + ${./example-skin-expected.yaml} + assertFileExists home-files/.config/k9s/skins/alt-skin.yaml assertFileContent \ - home-files/.config/k9s/hotkey.yml \ - ${./example-hotkey-expected.yml} - assertFileExists home-files/.config/k9s/aliases.yml + home-files/.config/k9s/skins/alt-skin.yaml \ + ${./example-skin-expected-alt.yaml} + assertFileExists home-files/.config/k9s/hotkey.yaml assertFileContent \ - home-files/.config/k9s/aliases.yml \ - ${./example-aliases-expected.yml} - assertFileExists home-files/.config/k9s/plugin.yml + home-files/.config/k9s/hotkey.yaml \ + ${./example-hotkey-expected.yaml} + assertFileExists home-files/.config/k9s/aliases.yaml assertFileContent \ - home-files/.config/k9s/plugin.yml \ - ${./example-plugin-expected.yml} - assertFileExists home-files/.config/k9s/views.yml + home-files/.config/k9s/aliases.yaml \ + ${./example-aliases-expected.yaml} + assertFileExists home-files/.config/k9s/plugin.yaml assertFileContent \ - home-files/.config/k9s/views.yml \ - ${./example-views-expected.yml} + home-files/.config/k9s/plugin.yaml \ + ${./example-plugin-expected.yaml} + assertFileExists home-files/.config/k9s/views.yaml + assertFileContent \ + home-files/.config/k9s/views.yaml \ + ${./example-views-expected.yaml} ''; } diff --git a/tests/modules/programs/k9s/example-skin-expected-alt.yaml b/tests/modules/programs/k9s/example-skin-expected-alt.yaml new file mode 100644 index 00000000..e78242ab --- /dev/null +++ b/tests/modules/programs/k9s/example-skin-expected-alt.yaml @@ -0,0 +1,8 @@ +k9s: + body: + bgColor: '#ffffff' + fgColor: orangered + logoColor: '#0000ff' + info: + fgColor: red + sectionColor: mediumvioletred diff --git a/tests/modules/programs/k9s/example-skin-expected.yml b/tests/modules/programs/k9s/example-skin-expected.yaml similarity index 100% rename from tests/modules/programs/k9s/example-skin-expected.yml rename to tests/modules/programs/k9s/example-skin-expected.yaml diff --git a/tests/modules/programs/k9s/example-views-expected.yml b/tests/modules/programs/k9s/example-views-expected.yaml similarity index 100% rename from tests/modules/programs/k9s/example-views-expected.yml rename to tests/modules/programs/k9s/example-views-expected.yaml diff --git a/tests/modules/programs/k9s/partial-skin-settings-expected.yaml b/tests/modules/programs/k9s/partial-skin-settings-expected.yaml new file mode 100644 index 00000000..8d8b0ef7 --- /dev/null +++ b/tests/modules/programs/k9s/partial-skin-settings-expected.yaml @@ -0,0 +1,7 @@ +k9s: + enableMouse: true + headless: false + maxConnRetry: 5 + refreshRate: 2 + ui: + skin: alt-skin diff --git a/tests/modules/programs/k9s/partial-skin-settings.nix b/tests/modules/programs/k9s/partial-skin-settings.nix new file mode 100644 index 00000000..ff296461 --- /dev/null +++ b/tests/modules/programs/k9s/partial-skin-settings.nix @@ -0,0 +1,53 @@ +{ config, ... }: + +# When not specified in `programs.k9s.settings.ui.skin`, +# test that the first skin name (alphabetically) is used in the config file + +{ + programs.k9s = { + enable = true; + settings = { + k9s = { + refreshRate = 2; + maxConnRetry = 5; + enableMouse = true; + headless = false; + }; + }; + skins = { + "default" = { + k9s = { + body = { + fgColor = "dodgerblue"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "lightskyblue"; + sectionColor = "steelblue"; + }; + }; + }; + "alt-skin" = { + k9s = { + body = { + fgColor = "orangered"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "red"; + sectionColor = "mediumvioletred"; + }; + }; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/k9s/config.yaml + assertFileContent \ + home-files/.config/k9s/config.yaml \ + ${./partial-skin-settings-expected.yaml} + ''; +}