From 7dc4e4ebd71280842b4d30975439980baaac9db8 Mon Sep 17 00:00:00 2001
From: Paul Meyer <49727155+katexochen@users.noreply.github.com>
Date: Sun, 23 Oct 2022 21:22:14 +0200
Subject: [PATCH] k9s: add module
---
.github/CODEOWNERS | 3 +
modules/lib/maintainers.nix | 6 ++
modules/misc/news.nix | 7 ++
modules/modules.nix | 1 +
modules/programs/k9s.nix | 65 +++++++++++++++++++
tests/default.nix | 1 +
tests/modules/programs/k9s/default.nix | 4 ++
tests/modules/programs/k9s/empty-settings.nix | 11 ++++
.../programs/k9s/example-config-expected.yml | 5 ++
.../modules/programs/k9s/example-settings.nix | 42 ++++++++++++
.../programs/k9s/example-skin-expected.yml | 8 +++
11 files changed, 153 insertions(+)
create mode 100644 modules/programs/k9s.nix
create mode 100644 tests/modules/programs/k9s/default.nix
create mode 100644 tests/modules/programs/k9s/empty-settings.nix
create mode 100644 tests/modules/programs/k9s/example-config-expected.yml
create mode 100644 tests/modules/programs/k9s/example-settings.nix
create mode 100644 tests/modules/programs/k9s/example-skin-expected.yml
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index b38049ed6..a500b20d5 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 0784c8a66..cbe779682 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 88a1dce96..b61a3af43 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 f2c6b1e98..5b228c5ff 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 000000000..11ac2bfd3
--- /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 efe2356fb..e84dbf053 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 000000000..58d9f32f3
--- /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 000000000..5084be4fe
--- /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 000000000..019ee7a72
--- /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 000000000..ffe521448
--- /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 000000000..94f7e6eb8
--- /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