From 0892cb05c7234df8076cdb222ab73bc4ba577978 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 9 Mar 2023 15:06:04 +0100 Subject: [PATCH] beets: add mpdIntegration Allow configuration of mpdstats and mpdupdate plugins for Beets using Home Manager. Signed-off-by: Sefa Eyeoglu --- .github/CODEOWNERS | 3 +- modules/programs/beets.nix | 65 +++++++++++++++++-- tests/default.nix | 1 + tests/modules/programs/beets/default.nix | 4 ++ .../programs/beets/mpdstats-expected.service | 7 ++ .../programs/beets/mpdstats-expected.yaml | 5 ++ tests/modules/programs/beets/mpdstats.nix | 25 +++++++ .../programs/beets/mpdupdate-expected.yaml | 5 ++ tests/modules/programs/beets/mpdupdate.nix | 20 ++++++ 9 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 tests/modules/programs/beets/default.nix create mode 100644 tests/modules/programs/beets/mpdstats-expected.service create mode 100644 tests/modules/programs/beets/mpdstats-expected.yaml create mode 100644 tests/modules/programs/beets/mpdstats.nix create mode 100644 tests/modules/programs/beets/mpdupdate-expected.yaml create mode 100644 tests/modules/programs/beets/mpdupdate.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2723ed8db847..c4a0d43c6e79 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -81,7 +81,8 @@ Makefile @thiagokokada /modules/programs/bat.nix @marsam -/modules/programs/beets.nix @rycee +/modules/programs/beets.nix @rycee @Scrumplex +/tests/modules/programs/beets @Scrumplex /modules/programs/bottom.nix @polykernel /tests/modules/programs/bottom @polykernel diff --git a/modules/programs/beets.nix b/modules/programs/beets.nix index fa959669c2f9..0aba9bc3e8b1 100644 --- a/modules/programs/beets.nix +++ b/modules/programs/beets.nix @@ -8,8 +8,28 @@ let yamlFormat = pkgs.formats.yaml { }; + mpdIntegrationOpts = with types; + submodule { + options = { + enableStats = mkEnableOption "mpdstats plugin and service"; + enableUpdate = mkEnableOption "mpdupdate plugin"; + host = mkOption { + type = str; + default = "localhost"; + description = "Host mpdstats will connect to"; + example = "10.0.0.42"; + }; + port = mkOption { + type = int; + default = config.services.mpd.network.port; + description = "Port mpdstats will connect to"; + example = "6600"; + }; + }; + }; + in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = with maintainers; [ rycee Scrumplex ]; options = { programs.beets = { @@ -48,13 +68,46 @@ in { $XDG_CONFIG_HOME/beets/config.yaml ''; }; + + mpdIntegration = mkOption { + type = mpdIntegrationOpts; + description = "Configuration for MPD related plugins"; + example = literalExpression '' + { + enableStats = true; + } + ''; + }; }; }; - config = mkIf cfg.enable { - home.packages = [ cfg.package ]; + config = mkIf cfg.enable (mkMerge [ + { + home.packages = [ cfg.package ]; - xdg.configFile."beets/config.yaml".source = - yamlFormat.generate "beets-config" cfg.settings; - }; + xdg.configFile."beets/config.yaml".source = + yamlFormat.generate "beets-config" cfg.settings; + } + (mkIf (cfg.mpdIntegration.enableStats || cfg.mpdIntegration.enableUpdate) { + programs.beets.settings.mpd = { + host = cfg.mpdIntegration.host; + port = cfg.mpdIntegration.port; + }; + }) + (mkIf cfg.mpdIntegration.enableStats { + programs.beets.settings.plugins = [ "mpdstats" ]; + + systemd.user.services."beets-mpdstats" = { + Unit = { + Description = "Beets MPDStats daemon"; + After = [ "mpd.service" ]; + Requires = [ "mpd.service" ]; + }; + Service.ExecStart = "${cfg.package}/bin/beet mpdstats"; + }; + }) + (mkIf cfg.mpdIntegration.enableUpdate { + programs.beets.settings.plugins = [ "mpdupdate" ]; + }) + ]); } diff --git a/tests/default.nix b/tests/default.nix index 495fd5ae51d6..c4fdab5c8d6e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -61,6 +61,7 @@ import nmt { ./modules/programs/autojump ./modules/programs/bash ./modules/programs/bat + ./modules/programs/beets ./modules/programs/bottom ./modules/programs/broot ./modules/programs/browserpass diff --git a/tests/modules/programs/beets/default.nix b/tests/modules/programs/beets/default.nix new file mode 100644 index 000000000000..f3e29d9d81e3 --- /dev/null +++ b/tests/modules/programs/beets/default.nix @@ -0,0 +1,4 @@ +{ + beets-mpdstats = ./mpdstats.nix; + beets-mpdupdate = ./mpdupdate.nix; +} diff --git a/tests/modules/programs/beets/mpdstats-expected.service b/tests/modules/programs/beets/mpdstats-expected.service new file mode 100644 index 000000000000..372879a44b99 --- /dev/null +++ b/tests/modules/programs/beets/mpdstats-expected.service @@ -0,0 +1,7 @@ +[Service] +ExecStart=@beets@/bin/beet mpdstats + +[Unit] +After=mpd.service +Description=Beets MPDStats daemon +Requires=mpd.service diff --git a/tests/modules/programs/beets/mpdstats-expected.yaml b/tests/modules/programs/beets/mpdstats-expected.yaml new file mode 100644 index 000000000000..f21a69213f9f --- /dev/null +++ b/tests/modules/programs/beets/mpdstats-expected.yaml @@ -0,0 +1,5 @@ +mpd: + host: localhost + port: 6600 +plugins: +- mpdstats diff --git a/tests/modules/programs/beets/mpdstats.nix b/tests/modules/programs/beets/mpdstats.nix new file mode 100644 index 000000000000..9d3ffce36e52 --- /dev/null +++ b/tests/modules/programs/beets/mpdstats.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + home.stateVersion = "23.05"; + + programs.beets = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; + mpdIntegration.enableStats = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/beets/config.yaml + assertFileContent \ + home-files/.config/beets/config.yaml \ + ${./mpdstats-expected.yaml} + + assertFileExists home-files/.config/systemd/user/beets-mpdstats.service + assertFileContent \ + home-files/.config/systemd/user/beets-mpdstats.service \ + ${./mpdstats-expected.service} + ''; + }; +} diff --git a/tests/modules/programs/beets/mpdupdate-expected.yaml b/tests/modules/programs/beets/mpdupdate-expected.yaml new file mode 100644 index 000000000000..1f998bd9a4dd --- /dev/null +++ b/tests/modules/programs/beets/mpdupdate-expected.yaml @@ -0,0 +1,5 @@ +mpd: + host: localhost + port: 6600 +plugins: +- mpdupdate diff --git a/tests/modules/programs/beets/mpdupdate.nix b/tests/modules/programs/beets/mpdupdate.nix new file mode 100644 index 000000000000..3516ae205424 --- /dev/null +++ b/tests/modules/programs/beets/mpdupdate.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + home.stateVersion = "23.05"; + + programs.beets = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; + mpdIntegration.enableUpdate = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/beets/config.yaml + assertFileContent \ + home-files/.config/beets/config.yaml \ + ${./mpdupdate-expected.yaml} + ''; + }; +}