diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-19 22:04:35 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-19 22:04:35 +0200 |
commit | 7ead226ea0871045fa66472bd7b0b0e570038ff1 (patch) | |
tree | f04a9966e52a3b32228427e423f08e5ee7a4bcb5 /modules | |
parent | modules/river/keymap: Avoid the inf-rec by explicitly using a fixpoint (diff) | |
download | nixos-config-7ead226ea0871045fa66472bd7b0b0e570038ff1.zip |
modules/yt: Use nix to generate the configs and update the config
Diffstat (limited to 'modules')
-rw-r--r-- | modules/by-name/yt/yt/config.toml | 12 | ||||
-rwxr-xr-x | modules/by-name/yt/yt/external_commands_script.sh | 9 | ||||
-rw-r--r-- | modules/by-name/yt/yt/input.conf | 14 | ||||
-rw-r--r-- | modules/by-name/yt/yt/input.conf.license | 9 | ||||
-rw-r--r-- | modules/by-name/yt/yt/module.nix | 91 | ||||
-rw-r--r-- | modules/by-name/yt/yt/mpv.conf | 1 | ||||
-rw-r--r-- | modules/by-name/yt/yt/mpv.conf.license | 9 |
7 files changed, 97 insertions, 48 deletions
diff --git a/modules/by-name/yt/yt/config.toml b/modules/by-name/yt/yt/config.toml deleted file mode 100644 index aecb74ba..00000000 --- a/modules/by-name/yt/yt/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -# nixos-config - My current NixOS configuration -# -# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of my nixos-config. -# -# You should have received a copy of the License along with this program. -# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -[download] -max_cache_size = "5 GiB" diff --git a/modules/by-name/yt/yt/external_commands_script.sh b/modules/by-name/yt/yt/external_commands_script.sh new file mode 100755 index 00000000..2e59e94a --- /dev/null +++ b/modules/by-name/yt/yt/external_commands_script.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env sh + +riverctl focus-output next + +alacritty --title "floating please" --command "$@" + +riverctl focus-output next + +# vim: ft=sh diff --git a/modules/by-name/yt/yt/input.conf b/modules/by-name/yt/yt/input.conf deleted file mode 100644 index 68dad824..00000000 --- a/modules/by-name/yt/yt/input.conf +++ /dev/null @@ -1,14 +0,0 @@ -c script-message yt-comments-external -C script-message yt-comments-local - -d script-message yt-description-external -D script-message yt-description-local - -WHEEL_LEFT playlist-prev -WHEEL_RIGHT playlist-next - -q script-message yt-mark-watched -Q script-message yt-mark-picked -r script-message yt-check-new-videos - -P quit diff --git a/modules/by-name/yt/yt/input.conf.license b/modules/by-name/yt/yt/input.conf.license deleted file mode 100644 index eae6a84c..00000000 --- a/modules/by-name/yt/yt/input.conf.license +++ /dev/null @@ -1,9 +0,0 @@ -nixos-config - My current NixOS configuration - -Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of my nixos-config. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/modules/by-name/yt/yt/module.nix b/modules/by-name/yt/yt/module.nix index 4e7e90fe..650f11a5 100644 --- a/modules/by-name/yt/yt/module.nix +++ b/modules/by-name/yt/yt/module.nix @@ -10,9 +10,94 @@ { config, lib, + pkgs, ... }: let cfg = config.soispha.programs.yt; + + mkConfig = (pkgs.formats.toml {}).generate; + + mpvInputConfig = { + "c" = "script-message yt-comments-external"; + "C" = "script-message yt-comments-local"; + + "d" = "script-message yt-description-external"; + "D" = "script-message yt-description-local"; + + "t" = "script-message yt-thumbnail-external"; + "I" = "script-message yt-info-external"; + + "WHEEL_LEFT" = "playlist-prev"; + "WHEEL_RIGHT" = "playlist-next"; + + "q" = "script-message yt-mark-watched"; + "Q" = "script-message yt-mark-picked"; + "r" = "script-message yt-check-new-videos"; + + "P" = "quit"; + }; + + mpvConf = { + "volume" = 75; + }; + + ytConfig = { + download = { + max_cache_size = "5 GiB"; + }; + + show = { + image_show_command = lib.getExe (pkgs.writeShellApplication { + name = "show_thumbnail"; + text = '' + imv -w "floating please" "$1" + ''; + runtimeInputs = [ + pkgs.imv + ]; + + inheritPath = false; + }); + }; + watch = { + external_command_spawn_script = lib.getExe (pkgs.writeShellApplication { + name = "start_external_command"; + text = builtins.readFile ./external_commands_script.sh; + runtimeInputs = [ + pkgs.river + pkgs.alacritty + ]; + + inheritPath = false; + }); + }; + }; + + inherit (lib) generators; + inherit (builtins) typeOf stringLength; + + renderOption = option: + rec { + int = toString option; + float = int; + bool = lib.hm.booleans.yesNo option; + string = option; + } + .${ + typeOf option + }; + + renderOptionValue = value: let + rendered = renderOption value; + length = toString (stringLength rendered); + in "%${length}%${rendered}"; + + renderOptions = generators.toKeyValue { + mkKeyValue = generators.mkKeyValueDefault {mkValueString = renderOptionValue;} "="; + listsAsDuplicateKeys = true; + }; + + renderBindings = bindings: lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") bindings); in { options.soispha.programs.yt = { enable = lib.mkEnableOption "the yt cli client"; @@ -21,9 +106,9 @@ in { config = { home-manager.users.soispha = lib.mkIf cfg.enable { xdg.configFile = { - "yt/mpv.conf".source = ./mpv.conf; - "yt/mpv.input.conf".source = ./input.conf; - "yt/config.toml".source = ./config.toml; + "yt/mpv.conf".text = renderOptions mpvConf; + "yt/mpv.input.conf".text = renderBindings mpvInputConfig; + "yt/config.toml".source = mkConfig "config.toml" ytConfig; }; }; }; diff --git a/modules/by-name/yt/yt/mpv.conf b/modules/by-name/yt/yt/mpv.conf deleted file mode 100644 index 52a40823..00000000 --- a/modules/by-name/yt/yt/mpv.conf +++ /dev/null @@ -1 +0,0 @@ -volume=75 diff --git a/modules/by-name/yt/yt/mpv.conf.license b/modules/by-name/yt/yt/mpv.conf.license deleted file mode 100644 index eae6a84c..00000000 --- a/modules/by-name/yt/yt/mpv.conf.license +++ /dev/null @@ -1,9 +0,0 @@ -nixos-config - My current NixOS configuration - -Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of my nixos-config. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. |