From de496c9ccb705ed76c1f23c2cad13e8970c37f0b Mon Sep 17 00:00:00 2001 From: awwpotato Date: Sat, 10 May 2025 18:08:10 -0700 Subject: [PATCH] television: add support for channels (#7026) --- modules/programs/television.nix | 52 ++++++++++++++++--- .../programs/television/basic-config.nix | 27 ++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/modules/programs/television.nix b/modules/programs/television.nix index e36aefb3e..45c73b528 100644 --- a/modules/programs/television.nix +++ b/modules/programs/television.nix @@ -18,6 +18,11 @@ in settings = lib.mkOption { type = tomlFormat.type; default = { }; + description = '' + Configuration written to {file}`$XDG_CONFIG_HOME/television/config.toml`. + See + for the full list of options. + ''; example = lib.literalExpression '' { tick_rate = 50; @@ -31,10 +36,35 @@ in }; } ''; + }; + + channels = lib.mkOption { + type = lib.types.attrsOf tomlFormat.type; + default = { }; description = '' - Configuration written to {file}`$XDG_CONFIG_HOME/television/config.toml`. - See - for the full list of options. + Each set of channels are written to + {file}`$XDG_CONFIG_HOME/television/NAME-channels.toml` + + See + for options + ''; + example = lib.literalExpression '' + { + my-custom = { + cable_channel = [ + { + name = "git-log"; + source_command = "git log --oneline --date=short --pretty=\"format:%h %s %an %cd\" \"$@\""; + preview_command = "git show -p --stat --pretty=fuller --color=always {0}"; + } + { + name = "git-log"; + source_command = "git log --oneline --date=short --pretty=\"format:%h %s %an %cd\" \"$@\""; + preview_command = "git show -p --stat --pretty=fuller --color=always {0}"; + } + ]; + }; + } ''; }; @@ -46,9 +76,19 @@ in config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."television/config.toml" = lib.mkIf (cfg.settings != { }) { - source = tomlFormat.generate "config.toml" cfg.settings; - }; + xdg.configFile = lib.mkMerge [ + { + "television/config.toml" = lib.mkIf (cfg.settings != { }) { + source = tomlFormat.generate "config.toml" cfg.settings; + }; + } + (lib.mapAttrs' ( + name: value: + lib.nameValuePair "television/${name}-channels.toml" { + source = tomlFormat.generate "television-${name}-channels" value; + } + ) cfg.channels) + ]; programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration '' eval "$(${lib.getExe cfg.package} init bash)" diff --git a/tests/modules/programs/television/basic-config.nix b/tests/modules/programs/television/basic-config.nix index cd2f0a59c..6d689f41b 100644 --- a/tests/modules/programs/television/basic-config.nix +++ b/tests/modules/programs/television/basic-config.nix @@ -10,6 +10,20 @@ input_bar_position = "top"; }; }; + channels.my-custom = { + cable_channel = [ + { + name = "git-log"; + source_command = ''git log --oneline --date=short --pretty="format:%h %s %an %cd" "$@"''; + preview_command = "git show -p --stat --pretty=fuller --color=always {0}"; + } + { + name = "my-dotfiles"; + source_command = "fd -t f . $HOME/.config"; + preview_command = "bat -n --color=always {0}"; + } + ]; + }; }; nmt.script = '' @@ -23,5 +37,18 @@ show_preview_panel = true use_nerd_font_icons = false ''} + assertFileExists home-files/.config/television/my-custom-channels.toml + assertFileContent home-files/.config/television/my-custom-channels.toml \ + ${pkgs.writeText "channels-expected" '' + [[cable_channel]] + name = "git-log" + preview_command = "git show -p --stat --pretty=fuller --color=always {0}" + source_command = "git log --oneline --date=short --pretty=\"format:%h %s %an %cd\" \"$@\"" + + [[cable_channel]] + name = "my-dotfiles" + preview_command = "bat -n --color=always {0}" + source_command = "fd -t f . $HOME/.config" + ''} ''; }