diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b38049ed..a500b20d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -155,6 +155,9 @@ Makefile @thiagokokada /modules/programs/just.nix @maximsmol +/modules/programs/k9s.nix @katexochen +/tests/modules/programs/k9s @katexochen + /modules/programs/keychain.nix @marsam /modules/programs/kodi.nix @dwagenk diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 0784c8a6..cbe77968 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -101,6 +101,12 @@ fingerprint = "2BE3 BAFD 793E A349 ED1F F00F 04D0 CEAF 916A 9A40"; }]; }; + katexochen = { + name = "Paul Meyer"; + email = "49727155+katexochen@users.noreply.github.com"; + github = "katexochen"; + githubId = 49727155; + }; kubukoz = { name = "Jakub Kozłowski"; email = "kubukoz@users.noreply.github.com"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 88a1dce9..b61a3af4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -793,6 +793,13 @@ in enabling this. ''; } + + { + time = "2022-10-24T22:05:27+00:00"; + message = '' + A new module is available: 'programs.k9s'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index f2c6b1e9..5b228c5f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -99,6 +99,7 @@ let ./programs/java.nix ./programs/jq.nix ./programs/just.nix + ./programs/k9s.nix ./programs/kakoune.nix ./programs/keychain.nix ./programs/kitty.nix diff --git a/modules/programs/k9s.nix b/modules/programs/k9s.nix new file mode 100644 index 00000000..11ac2bfd --- /dev/null +++ b/modules/programs/k9s.nix @@ -0,0 +1,65 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.k9s; + yamlFormat = pkgs.formats.yaml { }; + +in { + meta.maintainers = [ hm.maintainers.katexochen ]; + + options.programs.k9s = { + enable = + mkEnableOption "k9s - Kubernetes CLI To Manage Your Clusters In Style"; + + package = mkPackageOption pkgs "k9s" { }; + + settings = mkOption { + type = yamlFormat.type; + default = { }; + description = '' + Configuration written to + $XDG_CONFIG_HOME/k9s/config.yml. See + + for supported values. + ''; + example = literalExpression '' + k9s = { + refreshRate = 2; + }; + ''; + }; + + skin = mkOption { + type = yamlFormat.type; + default = { }; + description = '' + Skin written to + $XDG_CONFIG_HOME/k9s/skin.yml. See + + for supported values. + ''; + example = literalExpression '' + k9s = { + body = { + fgColor = "dodgerblue"; + }; + }; + ''; + }; + }; + + config = 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/skin.yml" = mkIf (cfg.skin != { }) { + source = yamlFormat.generate "k9s-skin" cfg.skin; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index efe2356f..e84dbf05 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -80,6 +80,7 @@ import nmt { ./modules/programs/hyfetch ./modules/programs/i3status ./modules/programs/irssi + ./modules/programs/k9s ./modules/programs/kakoune ./modules/programs/kitty ./modules/programs/less diff --git a/tests/modules/programs/k9s/default.nix b/tests/modules/programs/k9s/default.nix new file mode 100644 index 00000000..58d9f32f --- /dev/null +++ b/tests/modules/programs/k9s/default.nix @@ -0,0 +1,4 @@ +{ + k9s-example-settings = ./example-settings.nix; + k9s-empty-settings = ./empty-settings.nix; +} diff --git a/tests/modules/programs/k9s/empty-settings.nix b/tests/modules/programs/k9s/empty-settings.nix new file mode 100644 index 00000000..5084be4f --- /dev/null +++ b/tests/modules/programs/k9s/empty-settings.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + programs.k9s.enable = true; + + test.stubs.k9s = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/k9s + ''; +} diff --git a/tests/modules/programs/k9s/example-config-expected.yml b/tests/modules/programs/k9s/example-config-expected.yml new file mode 100644 index 00000000..019ee7a7 --- /dev/null +++ b/tests/modules/programs/k9s/example-config-expected.yml @@ -0,0 +1,5 @@ +k9s: + enableMouse: true + headless: false + maxConnRetry: 5 + refreshRate: 2 diff --git a/tests/modules/programs/k9s/example-settings.nix b/tests/modules/programs/k9s/example-settings.nix new file mode 100644 index 00000000..ffe52144 --- /dev/null +++ b/tests/modules/programs/k9s/example-settings.nix @@ -0,0 +1,42 @@ +{ config, ... }: + +{ + programs.k9s = { + enable = true; + package = config.lib.test.mkStubPackage { }; + + settings = { + k9s = { + refreshRate = 2; + maxConnRetry = 5; + enableMouse = true; + headless = false; + }; + }; + + skin = { + k9s = { + body = { + fgColor = "dodgerblue"; + bgColor = "#ffffff"; + logoColor = "#0000ff"; + }; + info = { + fgColor = "lightskyblue"; + sectionColor = "steelblue"; + }; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/k9s/config.yml + assertFileContent \ + home-files/.config/k9s/config.yml \ + ${./example-config-expected.yml} + assertFileExists home-files/.config/k9s/skin.yml + assertFileContent \ + home-files/.config/k9s/skin.yml \ + ${./example-skin-expected.yml} + ''; +} diff --git a/tests/modules/programs/k9s/example-skin-expected.yml b/tests/modules/programs/k9s/example-skin-expected.yml new file mode 100644 index 00000000..94f7e6eb --- /dev/null +++ b/tests/modules/programs/k9s/example-skin-expected.yml @@ -0,0 +1,8 @@ +k9s: + body: + bgColor: '#ffffff' + fgColor: dodgerblue + logoColor: '#0000ff' + info: + fgColor: lightskyblue + sectionColor: steelblue