diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e4f70fd6..0f1b4a66 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -440,6 +440,8 @@ Makefile @thiagokokada /modules/services/lieer.nix @tadfisher +/modules/services/listenbrainz-mpd.nix @Scrumplex + /modules/services/lorri.nix @Gerschtli /modules/services/mako.nix @onny diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 0b9af543..c7d536e9 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -948,6 +948,14 @@ in 'programs.i3status-rust.package' to an older version. ''; } + + { + time = "2023-03-22T07:20:00+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.listenbrainz-mpd'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 4110bfa4..74cf7c9d 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -243,6 +243,7 @@ let ./services/keybase.nix ./services/keynav.nix ./services/lieer.nix + ./services/listenbrainz-mpd.nix ./services/lorri.nix ./services/mako.nix ./services/mbsync.nix diff --git a/modules/services/listenbrainz-mpd.nix b/modules/services/listenbrainz-mpd.nix new file mode 100644 index 00000000..5a6d2082 --- /dev/null +++ b/modules/services/listenbrainz-mpd.nix @@ -0,0 +1,51 @@ +{ config, lib, pkgs, ... }: + +let + + inherit (lib.options) mkEnableOption mkPackageOption mkOption; + inherit (lib.modules) mkIf; + + cfg = config.services.listenbrainz-mpd; + + tomlFormat = pkgs.formats.toml { }; + +in { + meta.maintainers = [ lib.maintainers.Scrumplex ]; + + options.services.listenbrainz-mpd = { + enable = mkEnableOption "listenbrainz-mpd"; + + package = mkPackageOption pkgs "listenbrainz-mpd" { }; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + description = '' + Configuration for listenbrainz-mpd written to + $XDG_CONFIG_HOME/listenbrainz-mpd/config.toml. + ''; + example = { submission.tokenFile = "/run/secrets/listenbrainz-mpd"; }; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services."listenbrainz-mpd" = { + Unit = { + Description = "ListenBrainz submission client for MPD"; + Documentation = "https://codeberg.org/elomatreb/listenbrainz-mpd"; + After = [ "mpd.service" ]; + Requires = [ "mpd.service" ]; + }; + Service = { + ExecStart = "${cfg.package}/bin/listenbrainz-mpd"; + Restart = "always"; + RestartSec = 5; + }; + Install.WantedBy = [ "default.target" ]; + }; + + xdg.configFile."listenbrainz-mpd/config.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "listenbrainz-mpd.toml" cfg.settings; + }; + }; +}