From b62cad68b754224caec1e3b0dbadf86821b0b255 Mon Sep 17 00:00:00 2001 From: diniamo <55629891+diniamo@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:39:30 +0200 Subject: [PATCH] spotify-player: add module --- modules/lib/maintainers.nix | 6 + modules/misc/news.nix | 7 + modules/modules.nix | 1 + modules/programs/spotify-player.nix | 154 ++++++++++++++++++ tests/default.nix | 1 + .../modules/programs/spotify-player/app.toml | 9 + .../programs/spotify-player/default.nix | 1 + .../programs/spotify-player/keymap.toml | 19 +++ .../programs/spotify-player/settings.nix | 103 ++++++++++++ .../programs/spotify-player/theme.toml | 58 +++++++ 10 files changed, 359 insertions(+) create mode 100644 modules/programs/spotify-player.nix create mode 100644 tests/modules/programs/spotify-player/app.toml create mode 100644 tests/modules/programs/spotify-player/default.nix create mode 100644 tests/modules/programs/spotify-player/keymap.toml create mode 100644 tests/modules/programs/spotify-player/settings.nix create mode 100644 tests/modules/programs/spotify-player/theme.toml diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 727d4c3c..a2c56863 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -71,6 +71,12 @@ github = "Dines97"; githubId = 19364873; }; + diniamo = { + name = "diniamo"; + email = "diniamo69@gmail.com"; + github = "diniamo"; + githubId = 55629891; + }; dwagenk = { email = "dwagenk@mailbox.org"; github = "dwagenk"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 8e304545..ef5378af 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1491,6 +1491,13 @@ in { A new module is available: 'programs.tofi'. ''; } + + { + time = "2024-04-19T10:01:55+00:00"; + message = '' + A new module is available: 'programs.spotify-player'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index c283b071..51284102 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -211,6 +211,7 @@ let ./programs/sioyek.nix ./programs/skim.nix ./programs/sm64ex.nix + ./programs/spotify-player.nix ./programs/sqls.nix ./programs/ssh.nix ./programs/starship.nix diff --git a/modules/programs/spotify-player.nix b/modules/programs/spotify-player.nix new file mode 100644 index 00000000..83eefe12 --- /dev/null +++ b/modules/programs/spotify-player.nix @@ -0,0 +1,154 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) + mkEnableOption mkPackageOption mkOption types literalExpression mkIf; + + cfg = config.programs.spotify-player; + tomlFormat = pkgs.formats.toml { }; + +in { + meta.maintainers = with lib.hm.maintainers; [ diniamo ]; + + options.programs.spotify-player = { + enable = mkEnableOption "spotify-player"; + + package = mkPackageOption pkgs "spotify-player" { }; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + example = literalExpression '' + { + theme = "default"; + playback_window_position = "Top"; + copy_command = { + command = "wl-copy"; + args = []; + }; + device = { + audio_cache = false; + normalization = false; + }; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/spotify-player/app.toml`. + + See + + for the full list of options. + ''; + }; + + themes = mkOption { + type = types.listOf tomlFormat.type; + default = [ ]; + example = literalExpression '' + [ + { + name = "default2"; + palette = { + black = "black"; + red = "red"; + green = "green"; + yellow = "yellow"; + blue = "blue"; + magenta = "magenta"; + cyan = "cyan"; + white = "white"; + bright_black = "bright_black"; + bright_red = "bright_red"; + bright_green = "bright_green"; + bright_yellow = "bright_yellow"; + bright_blue = "bright_blue"; + bright_magenta = "bright_magenta"; + bright_cyan = "bright_cyan"; + bright_white = "bright_white"; + }; + component_style = { + block_title = { fg = "Magenta"; }; + border = {}; + playback_track = { fg = "Cyan"; modifiers = ["Bold"]; }; + playback_artists = { fg = "Cyan"; modifiers = ["Bold"]; }; + playback_album = { fg = "Yellow"; }; + playback_metadata = { fg = "BrightBlack"; }; + playback_progress_bar = { bg = "BrightBlack"; fg = "Green"; }; + current_playing = { fg = "Green"; modifiers = ["Bold"]; }; + page_desc = { fg = "Cyan"; modifiers = ["Bold"]; }; + table_header = { fg = "Blue"; }; + selection = { modifiers = ["Bold" "Reversed"]; }; + }; + } + ] + ''; + description = '' + Configuration written to the `themes` field of + {file}`$XDG_CONFIG_HOME/spotify-player/theme.toml`. + + See + + for the full list of options. + ''; + }; + + keymaps = mkOption { + type = types.listOf tomlFormat.type; + default = [ ]; + example = literalExpression '' + [ + { + command = "NextTrack"; + key_sequence = "g n"; + } + { + command = "PreviousTrack"; + key_sequence = "g p"; + } + { + command = "Search"; + key_sequence = "C-c C-x /"; + } + { + command = "ResumePause"; + key_sequence = "M-enter"; + } + { + command = "None"; + key_sequence = "q"; + } + ] + ''; + description = '' + Configuration written to the `keymaps` field of + {file}`$XDG_CONFIG_HOME/spotify-player/keymap.toml`. + + See + + for the full list of options. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile = { + "spotify-player/app.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "spotify-player-app" cfg.settings; + }; + + "spotify-player/theme.toml" = mkIf (cfg.themes != [ ]) { + source = + tomlFormat.generate "spotify-player-theme" { inherit (cfg) themes; }; + }; + + "spotify-player/keymap.toml" = mkIf (cfg.keymaps != [ ]) { + source = tomlFormat.generate "spotify-player-keymap" { + inherit (cfg) keymaps; + }; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index c95b288a..c4d98ef2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -140,6 +140,7 @@ in import nmtSrc { ./modules/programs/sftpman ./modules/programs/sioyek ./modules/programs/sm64ex + ./modules/programs/spotify-player ./modules/programs/ssh ./modules/programs/starship ./modules/programs/taskwarrior diff --git a/tests/modules/programs/spotify-player/app.toml b/tests/modules/programs/spotify-player/app.toml new file mode 100644 index 00000000..408e84b0 --- /dev/null +++ b/tests/modules/programs/spotify-player/app.toml @@ -0,0 +1,9 @@ +playback_window_position = "Top" +theme = "default" +[copy_command] +args = [] +command = "wl-copy" + +[device] +audio_cache = false +normalization = false diff --git a/tests/modules/programs/spotify-player/default.nix b/tests/modules/programs/spotify-player/default.nix new file mode 100644 index 00000000..9812b128 --- /dev/null +++ b/tests/modules/programs/spotify-player/default.nix @@ -0,0 +1 @@ +{ spotify-player-settings = ./settings.nix; } diff --git a/tests/modules/programs/spotify-player/keymap.toml b/tests/modules/programs/spotify-player/keymap.toml new file mode 100644 index 00000000..d11c86e4 --- /dev/null +++ b/tests/modules/programs/spotify-player/keymap.toml @@ -0,0 +1,19 @@ +[[keymaps]] +command = "NextTrack" +key_sequence = "g n" + +[[keymaps]] +command = "PreviousTrack" +key_sequence = "g p" + +[[keymaps]] +command = "Search" +key_sequence = "C-c C-x /" + +[[keymaps]] +command = "ResumePause" +key_sequence = "M-enter" + +[[keymaps]] +command = "None" +key_sequence = "q" diff --git a/tests/modules/programs/spotify-player/settings.nix b/tests/modules/programs/spotify-player/settings.nix new file mode 100644 index 00000000..dc7fe8c6 --- /dev/null +++ b/tests/modules/programs/spotify-player/settings.nix @@ -0,0 +1,103 @@ +{ + programs.spotify-player = { + enable = true; + + settings = { + theme = "default"; + playback_window_position = "Top"; + copy_command = { + command = "wl-copy"; + args = [ ]; + }; + device = { + audio_cache = false; + normalization = false; + }; + }; + + themes = [{ + name = "default2"; + palette = { + black = "black"; + red = "red"; + green = "green"; + yellow = "yellow"; + blue = "blue"; + magenta = "magenta"; + cyan = "cyan"; + white = "white"; + bright_black = "bright_black"; + bright_red = "bright_red"; + bright_green = "bright_green"; + bright_yellow = "bright_yellow"; + bright_blue = "bright_blue"; + bright_magenta = "bright_magenta"; + bright_cyan = "bright_cyan"; + bright_white = "bright_white"; + }; + component_style = { + block_title = { fg = "Magenta"; }; + border = { }; + playback_track = { + fg = "Cyan"; + modifiers = [ "Bold" ]; + }; + playback_artists = { + fg = "Cyan"; + modifiers = [ "Bold" ]; + }; + playback_album = { fg = "Yellow"; }; + playback_metadata = { fg = "BrightBlack"; }; + playback_progress_bar = { + bg = "BrightBlack"; + fg = "Green"; + }; + current_playing = { + fg = "Green"; + modifiers = [ "Bold" ]; + }; + page_desc = { + fg = "Cyan"; + modifiers = [ "Bold" ]; + }; + table_header = { fg = "Blue"; }; + selection = { modifiers = [ "Bold" "Reversed" ]; }; + }; + }]; + + keymaps = [ + { + command = "NextTrack"; + key_sequence = "g n"; + } + { + command = "PreviousTrack"; + key_sequence = "g p"; + } + { + command = "Search"; + key_sequence = "C-c C-x /"; + } + { + command = "ResumePause"; + key_sequence = "M-enter"; + } + { + command = "None"; + key_sequence = "q"; + } + ]; + }; + + test.stubs.spotify-player = { }; + + nmt.script = '' + assertFileContent home-files/.config/spotify-player/app.toml ${./app.toml} + assertFileContent home-files/.config/spotify-player/theme.toml ${ + ./theme.toml + } + assertFileContent home-files/.config/spotify-player/keymap.toml ${ + ./keymap.toml + } + ''; +} diff --git a/tests/modules/programs/spotify-player/theme.toml b/tests/modules/programs/spotify-player/theme.toml new file mode 100644 index 00000000..cb5fa99d --- /dev/null +++ b/tests/modules/programs/spotify-player/theme.toml @@ -0,0 +1,58 @@ +[[themes]] +name = "default2" + +[themes.component_style] +[themes.component_style.block_title] +fg = "Magenta" + +[themes.component_style.border] + +[themes.component_style.current_playing] +fg = "Green" +modifiers = ["Bold"] + +[themes.component_style.page_desc] +fg = "Cyan" +modifiers = ["Bold"] + +[themes.component_style.playback_album] +fg = "Yellow" + +[themes.component_style.playback_artists] +fg = "Cyan" +modifiers = ["Bold"] + +[themes.component_style.playback_metadata] +fg = "BrightBlack" + +[themes.component_style.playback_progress_bar] +bg = "BrightBlack" +fg = "Green" + +[themes.component_style.playback_track] +fg = "Cyan" +modifiers = ["Bold"] + +[themes.component_style.selection] +modifiers = ["Bold", "Reversed"] + +[themes.component_style.table_header] +fg = "Blue" + +[themes.palette] +black = "black" +blue = "blue" +bright_black = "bright_black" +bright_blue = "bright_blue" +bright_cyan = "bright_cyan" +bright_green = "bright_green" +bright_magenta = "bright_magenta" +bright_red = "bright_red" +bright_white = "bright_white" +bright_yellow = "bright_yellow" +cyan = "cyan" +green = "green" +magenta = "magenta" +red = "red" +white = "white" +yellow = "yellow"