diff --git a/modules/misc/news/2025/09/2025-09-06_10-04-11.nix b/modules/misc/news/2025/09/2025-09-06_10-04-11.nix new file mode 100644 index 000000000..15e3f8f56 --- /dev/null +++ b/modules/misc/news/2025/09/2025-09-06_10-04-11.nix @@ -0,0 +1,11 @@ +{ + time = "2025-09-06T17:04:11+00:00"; + condition = true; + message = '' + A new module is available: 'programs.pianobar'. + + `pianobar` is a console front-end for Pandora.com and provides options to + extend with third-party applications or scripts. This module enables + declarative configuration of all documented options. + ''; +} diff --git a/modules/programs/pianobar.nix b/modules/programs/pianobar.nix new file mode 100644 index 000000000..114a884dd --- /dev/null +++ b/modules/programs/pianobar.nix @@ -0,0 +1,101 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit (lib) + mkEnableOption + mkIf + mkOption + mkPackageOption + literalExpression + ; + + inherit (lib.types) + nonEmptyStr + submodule + ; + + inherit (pkgs.formats) + keyValue + ; + + keyValueFormat = keyValue { }; + + cfg = config.programs.pianobar; +in +{ + meta.maintainers = [ + # lib.maintainers.S0AndS0 + ## TODO: Trade above for below when `node.nixpkgs.locked.rev` is at or beyond + ## 4d48a4e93b9ffbd291b2d9ca3315848e27eed800 + { + name = "S0AndS0"; + email = "S0AndS0@digital-mercenaries.com"; + github = "S0AndS0"; + githubId = 4116150; + matrix = "@s0ands0:matrix.org"; + } + ]; + + options.programs.pianobar = { + enable = mkEnableOption "Enable pianobar"; + + package = mkPackageOption pkgs "pianobar" { + nullable = true; + }; + + settings = mkOption { + type = submodule { + freeformType = keyValueFormat.type; + options = { + user = mkOption { + description = "Username or emaill address for Pandora music service authentication"; + example = ''"groovy-tunes@example.com"''; + type = nonEmptyStr; + }; + + password_command = mkOption { + description = "Command pianobar will use to access password for Pandora music service authentication"; + example = ''"cat /run/secrets/pianobar/groovy-tunes"''; + type = nonEmptyStr; + }; + }; + }; + + default = { }; + + description = '' + Apply configurations for `pianobar` via key/value attributes. + + Note; it is recommended to use `sops-nix`, or similar, secrets + management solution for providing + `programs.pianobar.settings.password_command` value. + ''; + + example = literalExpression '' + { + programs.pianobar = { + enable = true; + settings = { + user = "groovy-tunes@example.com"; + password_command = "cat /run/secrets/pianobar/groovy-tunes"; + }; + }; + } + ''; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."pianobar/config" = lib.mkIf (cfg.settings != { }) { + source = keyValueFormat.generate "pianobar-config" cfg.settings; + }; + + home.packages = mkIf (cfg.package != null) [ + cfg.package + ]; + }; +} diff --git a/tests/modules/programs/pianobar/default.nix b/tests/modules/programs/pianobar/default.nix new file mode 100644 index 000000000..4873af8e4 --- /dev/null +++ b/tests/modules/programs/pianobar/default.nix @@ -0,0 +1,4 @@ +{ + pianobar-minimally-required-configs = ./minimally-required-configs.nix; + pianobar-extra-settings = ./extra-settings.nix; +} diff --git a/tests/modules/programs/pianobar/extra-settings.conf b/tests/modules/programs/pianobar/extra-settings.conf new file mode 100644 index 000000000..2d8c35c86 --- /dev/null +++ b/tests/modules/programs/pianobar/extra-settings.conf @@ -0,0 +1,29 @@ +act_help=h +act_history=? +at_icon=@ +audio_pipe=/path/to/fifo +audio_quality=low +autoselect={1,0} +autostart_station=123456 +bind_to={if!tunX,host!127.0.0.1} +buffer_seconds=5 +ca_bundle=/etc/ssl/certs/ca-certificates.crt +control_proxy=http://user:password@host:port/ +event_command=/home/user/.config/pianobar/eventcmd +fifo=/home/user/.config/pianobar/cmd +format_list_song=%i) %a - %t%r +format_msg_none=%s +gain_mul=1.0 +history=5 +host=tuner.pandora.com +love_icon=<3 +max_retry=3 +password_command=cat /run/secrets/pianobar/groovy-tunes +proxy=http://user:password@host:port/ +sample_rate=0 +sort={name_az, name_za, quickmix_01_name_az, quickmix_01_name_za, quickmix_10_name_az, quickmix_10_name_za} +timeout=30 +tired_icon=zZ +tls_port=443 +user=groovy-tunes@example.com +volume=30 diff --git a/tests/modules/programs/pianobar/extra-settings.nix b/tests/modules/programs/pianobar/extra-settings.nix new file mode 100644 index 000000000..8c14b276f --- /dev/null +++ b/tests/modules/programs/pianobar/extra-settings.nix @@ -0,0 +1,42 @@ +{ + programs.pianobar = { + enable = true; + settings = { + act_help = "h"; + act_history = "?"; + at_icon = "@"; + audio_pipe = "/path/to/fifo"; + audio_quality = "low"; + autoselect = "{1,0}"; + autostart_station = "123456"; + bind_to = "{if!tunX,host!127.0.0.1}"; + buffer_seconds = "5"; + ca_bundle = "/etc/ssl/certs/ca-certificates.crt"; + control_proxy = "http://user:password@host:port/"; + event_command = "/home/user/.config/pianobar/eventcmd"; + fifo = "/home/user/.config/pianobar/cmd"; + format_list_song = "%i) %a - %t%r"; + format_msg_none = "%s"; + gain_mul = "1.0"; + history = "5"; + host = "tuner.pandora.com"; + love_icon = "<3"; + max_retry = "3"; + password_command = "cat /run/secrets/pianobar/groovy-tunes"; + proxy = "http://user:password@host:port/"; + sample_rate = "0"; + sort = "{name_az, name_za, quickmix_01_name_az, quickmix_01_name_za, quickmix_10_name_az, quickmix_10_name_za}"; + timeout = "30"; + tired_icon = "zZ"; + tls_port = "443"; + user = "groovy-tunes@example.com"; + volume = "30"; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/pianobar/config + assertFileContent home-files/.config/pianobar/config \ + ${./extra-settings.conf} + ''; +} diff --git a/tests/modules/programs/pianobar/minimally-required-configs.conf b/tests/modules/programs/pianobar/minimally-required-configs.conf new file mode 100644 index 000000000..887e49afc --- /dev/null +++ b/tests/modules/programs/pianobar/minimally-required-configs.conf @@ -0,0 +1,2 @@ +password_command=cat /run/secrets/pianobar/groovy-tunes +user=groovy-tunes@example.com diff --git a/tests/modules/programs/pianobar/minimally-required-configs.nix b/tests/modules/programs/pianobar/minimally-required-configs.nix new file mode 100644 index 000000000..4af49501e --- /dev/null +++ b/tests/modules/programs/pianobar/minimally-required-configs.nix @@ -0,0 +1,15 @@ +{ + programs.pianobar = { + enable = true; + settings = { + password_command = "cat /run/secrets/pianobar/groovy-tunes"; + user = "groovy-tunes@example.com"; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/pianobar/config + assertFileContent home-files/.config/pianobar/config \ + ${./minimally-required-configs.conf} + ''; +}