1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-28 05:01:01 +01:00

mpd: use XDG music dir if XDG user dirs are enabled

If the user has enabled the XDG user directories module then we can
use the XDG music directory in the MPD module. Otherwise we'll leave
the option undefined so that the user is forced to define the
directory to use.

This applies to state version 22.11 and above.

Fixes #3225
This commit is contained in:
Robert Helgesson 2022-09-15 22:19:00 +02:00
parent b0247ceedc
commit 5427f3d1f0
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
10 changed files with 98 additions and 6 deletions

View file

@ -52,11 +52,18 @@ in {
musicDirectory = mkOption {
type = with types; either path str;
default = "${config.home.homeDirectory}/music";
defaultText = "$HOME/music";
defaultText = literalExpression ''
''${home.homeDirectory}/music if state version < 22.11
''${xdg.userDirs.music} if xdg.userDirs.enable == true
undefined otherwise
'';
apply = toString; # Prevent copies to Nix store.
description = ''
The directory where mpd reads music from.
</para><para>
If <xref linkend="opt-xdg.userDirs.enable"/> is
<literal>true</literal> then the defined XDG music directory is used.
Otherwise, you must explicitly specify a value.
'';
};
@ -146,6 +153,17 @@ in {
(lib.hm.assertions.assertPlatform "services.mpd" pkgs lib.platforms.linux)
];
services.mpd = mkMerge [
(mkIf (versionAtLeast config.home.stateVersion "22.11"
&& config.xdg.userDirs.enable) {
musicDirectory = mkOptionDefault config.xdg.userDirs.music;
})
(mkIf (versionOlder config.home.stateVersion "22.11") {
musicDirectory = mkOptionDefault "${config.home.homeDirectory}/music";
})
];
systemd.user.services.mpd = {
Unit = {
After = [ "network.target" "sound.target" ];
@ -164,6 +182,7 @@ in {
${pkgs.bash}/bin/bash -c "${pkgs.coreutils}/bin/mkdir -p '${cfg.dataDir}' '${cfg.playlistDirectory}'"'';
};
};
systemd.user.sockets.mpd = mkIf cfg.network.startWhenNeeded {
Socket = {
ListenStream = let