1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00

k9s: v0.29/v0.30 compatibility

- Add `skins` option for definition of multiple skin files
- Change file extension to ".yaml"
- Deprecate `skin` option (points to `skins.skin`)
This commit is contained in:
Lucas Wagler 2024-01-21 23:17:27 +00:00 committed by GitHub
parent 0021558dba
commit 020399c287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 212 additions and 59 deletions

View file

@ -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";

View file

@ -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
<https://k9scli.io/topics/config/> 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
<https://k9scli.io/topics/skins/> 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
<https://k9scli.io/topics/aliases/> 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
<https://k9scli.io/topics/hotkeys/> 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
<https://k9scli.io/topics/plugins/> 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 <https://k9scli.io/topics/columns/> 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;
};
}

View file

@ -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;
}

View file

@ -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}
'';
}

View file

@ -3,3 +3,5 @@ k9s:
headless: false
maxConnRetry: 5
refreshRate: 2
ui:
skin: default

View file

@ -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}
'';
}

View file

@ -0,0 +1,8 @@
k9s:
body:
bgColor: '#ffffff'
fgColor: orangered
logoColor: '#0000ff'
info:
fgColor: red
sectionColor: mediumvioletred

View file

@ -0,0 +1,7 @@
k9s:
enableMouse: true
headless: false
maxConnRetry: 5
refreshRate: 2
ui:
skin: alt-skin

View file

@ -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}
'';
}