2022-10-23 21:22:14 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.k9s;
|
|
|
|
yamlFormat = pkgs.formats.yaml { };
|
2024-04-10 13:34:46 +02:00
|
|
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
2022-10-23 21:22:14 +02:00
|
|
|
|
|
|
|
in {
|
2024-09-09 08:34:44 +02:00
|
|
|
meta.maintainers = with maintainers; [ liyangau hm.maintainers.LucasWagler ];
|
2024-01-22 00:17:27 +01:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "k9s" "skin" ] [
|
|
|
|
"programs"
|
|
|
|
"k9s"
|
|
|
|
"skins"
|
|
|
|
"skin"
|
|
|
|
])
|
|
|
|
];
|
2022-10-23 21:22:14 +02:00
|
|
|
|
|
|
|
options.programs.k9s = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable =
|
|
|
|
mkEnableOption "k9s - Kubernetes CLI To Manage Your Clusters In Style";
|
2022-10-23 21:22:14 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
package = mkPackageOption pkgs "k9s" { };
|
2022-10-23 21:22:14 +02:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = yamlFormat.type;
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yaml` (linux)
|
|
|
|
or {file}`Library/Application Support/k9s/config.yaml` (darwin), See
|
2023-11-02 07:51:00 +01:00
|
|
|
<https://k9scli.io/topics/config/> for supported values.
|
2022-10-23 21:22:14 +02:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
k9s = {
|
|
|
|
refreshRate = 2;
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-22 00:17:27 +01:00
|
|
|
skins = mkOption {
|
2023-11-13 13:44:03 +01:00
|
|
|
type = with types; attrsOf (either yamlFormat.type path);
|
2022-10-23 21:22:14 +02:00
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Skin files written to {file}`$XDG_CONFIG_HOME/k9s/skins/` (linux)
|
|
|
|
or {file}`Library/Application Support/k9s/skins/` (darwin). See
|
2023-11-02 07:51:00 +01:00
|
|
|
<https://k9scli.io/topics/skins/> for supported values.
|
2022-10-23 21:22:14 +02:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
2023-11-13 13:44:03 +01:00
|
|
|
{
|
|
|
|
my_blue_skin = {
|
|
|
|
k9s = {
|
|
|
|
body = {
|
|
|
|
fgColor = "dodgerblue";
|
|
|
|
};
|
2024-01-22 00:17:27 +01:00
|
|
|
};
|
2022-10-23 21:22:14 +02:00
|
|
|
};
|
2023-11-13 13:44:03 +01:00
|
|
|
my_red_skin = ./red_skin.yaml;
|
|
|
|
}
|
2022-10-23 21:22:14 +02:00
|
|
|
'';
|
|
|
|
};
|
2023-11-01 18:40:14 +01:00
|
|
|
|
2023-11-02 07:51:00 +01:00
|
|
|
aliases = mkOption {
|
|
|
|
type = yamlFormat.type;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yaml` (linux)
|
|
|
|
or {file}`Library/Application Support/k9s/aliases.yaml` (darwin). See
|
2023-11-02 07:51:00 +01:00
|
|
|
<https://k9scli.io/topics/aliases/> for supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
alias = {
|
|
|
|
# Use pp as an alias for Pod
|
|
|
|
pp = "v1/pods";
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-01 18:40:14 +01:00
|
|
|
hotkey = mkOption {
|
|
|
|
type = yamlFormat.type;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkeys.yaml` (linux)
|
|
|
|
or {file}`Library/Application Support/k9s/hotkeys.yaml` (darwin). See
|
2023-11-02 07:51:00 +01:00
|
|
|
<https://k9scli.io/topics/hotkeys/> for supported values.
|
2023-11-01 18:40:14 +01:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
hotkey = {
|
|
|
|
# Make sure this is camel case
|
|
|
|
hotKey = {
|
|
|
|
shift-0 = {
|
|
|
|
shortCut = "Shift-0";
|
|
|
|
description = "Viewing pods";
|
|
|
|
command = "pods";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
2023-11-02 07:51:00 +01:00
|
|
|
|
|
|
|
plugin = mkOption {
|
|
|
|
type = yamlFormat.type;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugins.yaml (linux)`
|
|
|
|
or {file}`Library/Application Support/k9s/plugins.yaml` (darwin). See
|
2023-11-02 07:51:00 +01:00
|
|
|
<https://k9scli.io/topics/plugins/> for supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
plugin = {
|
|
|
|
# Defines a plugin to provide a `ctrl-l` shortcut to
|
|
|
|
# tail the logs while in pod view.
|
|
|
|
fred = {
|
|
|
|
shortCut = "Ctrl-L";
|
|
|
|
description = "Pod logs";
|
|
|
|
scopes = [ "po" ];
|
|
|
|
command = "kubectl";
|
|
|
|
background = false;
|
|
|
|
args = [
|
|
|
|
"logs"
|
|
|
|
"-f"
|
|
|
|
"$NAME"
|
|
|
|
"-n"
|
|
|
|
"$NAMESPACE"
|
|
|
|
"--context"
|
|
|
|
"$CLUSTER"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
views = mkOption {
|
|
|
|
type = yamlFormat.type;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
2024-04-10 13:34:46 +02:00
|
|
|
Resource column views written to
|
|
|
|
{file}`$XDG_CONFIG_HOME/k9s/views.yaml (linux)`
|
|
|
|
or {file}`Library/Application Support/k9s/views.yaml` (darwin).
|
2023-11-02 07:51:00 +01:00
|
|
|
See <https://k9scli.io/topics/columns/> for supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
k9s = {
|
|
|
|
views = {
|
|
|
|
"v1/pods" = {
|
|
|
|
columns = [
|
|
|
|
"AGE"
|
|
|
|
"NAMESPACE"
|
|
|
|
"NAME"
|
|
|
|
"IP"
|
|
|
|
"NODE"
|
|
|
|
"STATUS"
|
|
|
|
"READY"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
2022-10-23 21:22:14 +02:00
|
|
|
};
|
|
|
|
|
2024-01-22 00:17:27 +01:00
|
|
|
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:
|
2024-04-10 13:34:46 +02:00
|
|
|
nameValuePair (if !(isDarwin && !config.xdg.enable) then
|
|
|
|
"k9s/skins/${name}.yaml"
|
|
|
|
else
|
|
|
|
"Library/Application Support/k9s/skins/${name}.yaml") {
|
2023-11-13 13:44:03 +01:00
|
|
|
source = if lib.types.path.check value then
|
|
|
|
value
|
|
|
|
else
|
|
|
|
yamlFormat.generate "k9s-skin-${name}.yaml" value;
|
2024-04-10 13:34:46 +02:00
|
|
|
}) cfg.skins;
|
|
|
|
|
|
|
|
enableXdgConfig = !isDarwin || config.xdg.enable;
|
|
|
|
|
2024-01-22 00:17:27 +01:00
|
|
|
in mkIf cfg.enable {
|
2022-10-23 21:22:14 +02:00
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2024-04-10 13:34:46 +02:00
|
|
|
xdg.configFile = mkIf enableXdgConfig ({
|
2024-01-22 00:17:27 +01:00
|
|
|
"k9s/config.yaml" = mkIf (cfg.settings != { }) {
|
|
|
|
source = yamlFormat.generate "k9s-config"
|
|
|
|
(lib.recursiveUpdate skinSetting cfg.settings);
|
|
|
|
};
|
2023-11-01 18:40:14 +01:00
|
|
|
|
2024-01-22 00:17:27 +01:00
|
|
|
"k9s/aliases.yaml" = mkIf (cfg.aliases != { }) {
|
|
|
|
source = yamlFormat.generate "k9s-aliases" cfg.aliases;
|
|
|
|
};
|
2023-11-02 07:51:00 +01:00
|
|
|
|
2024-04-10 10:24:46 +02:00
|
|
|
"k9s/hotkeys.yaml" = mkIf (cfg.hotkey != { }) {
|
2024-01-22 00:17:27 +01:00
|
|
|
source = yamlFormat.generate "k9s-hotkey" cfg.hotkey;
|
|
|
|
};
|
2023-11-02 07:51:00 +01:00
|
|
|
|
2024-04-10 10:24:46 +02:00
|
|
|
"k9s/plugins.yaml" = mkIf (cfg.plugin != { }) {
|
2024-01-22 00:17:27 +01:00
|
|
|
source = yamlFormat.generate "k9s-plugin" cfg.plugin;
|
|
|
|
};
|
2023-11-02 07:51:00 +01:00
|
|
|
|
2024-01-22 00:17:27 +01:00
|
|
|
"k9s/views.yaml" = mkIf (cfg.views != { }) {
|
|
|
|
source = yamlFormat.generate "k9s-views" cfg.views;
|
|
|
|
};
|
2024-04-10 13:34:46 +02:00
|
|
|
} // 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);
|
2022-10-23 21:22:14 +02:00
|
|
|
};
|
|
|
|
}
|