about summary refs log tree commit diff
path: root/modules/services/audio
diff options
context:
space:
mode:
authorRickard Nilsson <rickynils@gmail.com>2013-01-27 20:21:04 +0100
committerRickard Nilsson <rickynils@gmail.com>2013-01-27 20:21:04 +0100
commit45522d080681fb6382a60be8069998ca468c9146 (patch)
treeef5497f25f399b316cf536f9405abd85322b09f9 /modules/services/audio
parent27414c4656cb8bf4afba7c28d868b91869b1201e (diff)
downloadnixlib-45522d080681fb6382a60be8069998ca468c9146.tar
nixlib-45522d080681fb6382a60be8069998ca468c9146.tar.gz
nixlib-45522d080681fb6382a60be8069998ca468c9146.tar.bz2
nixlib-45522d080681fb6382a60be8069998ca468c9146.tar.lz
nixlib-45522d080681fb6382a60be8069998ca468c9146.tar.xz
nixlib-45522d080681fb6382a60be8069998ca468c9146.tar.zst
nixlib-45522d080681fb6382a60be8069998ca468c9146.zip
mpd: Adjust service definition to systemd
Diffstat (limited to 'modules/services/audio')
-rw-r--r--modules/services/audio/mpd.nix126
1 files changed, 59 insertions, 67 deletions
diff --git a/modules/services/audio/mpd.nix b/modules/services/audio/mpd.nix
index 4a7ae355e4c1..85a87dfe845c 100644
--- a/modules/services/audio/mpd.nix
+++ b/modules/services/audio/mpd.nix
@@ -6,93 +6,85 @@ let
 
   uid = config.ids.uids.mpd;
   gid = config.ids.gids.mpd;
+  cfg = config.services.mpd;
 
-in
+  mpdConf = pkgs.writeText "mpd.conf" ''
+    music_directory     "${cfg.musicDirectory}"
+    playlist_directory  "${cfg.dataDir}/playlists"
+    db_file             "${cfg.dataDir}/tag_cache"
+    state_file          "${cfg.dataDir}/state"
+    sticker_file        "${cfg.dataDir}/sticker.sql"
+    log_file            "syslog"
+    user                "mpd"
+    ${cfg.extraConfig}
+  ''; 
 
-{
+in {
 
   ###### interface
 
-  options = {
+  options = { 
 
-    services.mpd = {
+    services.mpd = { 
 
       enable = mkOption {
         default = false;
         description = ''
-          Whether to enable the MPD music player daemon (server).
-        '';
-      };
-
-      conffile = mkOption {
-        default = ''
-          music_directory     "${config.services.mpd.dataDir}/music"
-          playlist_directory  "${config.services.mpd.dataDir}/playlists"
-          db_file             "${config.services.mpd.dataDir}/tag_cache"
-          state_file          "${config.services.mpd.dataDir}/state"
-          sticker_file        "${config.services.mpd.dataDir}/sticker.sql"
-          log_file            "/var/log/mpd.log"
-          pid_file            "/var/run/mpd/mpd.pid"
-          bind_to_address     "localhost"
-          user                "mpd"
-        '';
-        description = ''The contents of the MPD configuration file mpd.conf'';
-      };
+          Whether to enable MPD, the music player daemon.
+        ''; 
+      };  
+
+      musicDirectory = mkOption {
+        default = "${cfg.dataDir}/music";
+        description = ''
+          Extra configuration added to the end of MPD's
+          configuration file, mpd.conf.
+        ''; 
+      };  
+
+      extraConfig = mkOption {
+        default = ""; 
+        description = ''
+          Extra directives added to to the end of MPD's configuration file,
+          mpd.conf. Basic configuration like file location and uid/gid
+          is added automatically to the beginning of the file.
+        ''; 
+      };  
 
       dataDir = mkOption {
         default = "/var/lib/mpd/";
-        example = "debug";
         description = ''
-          The root directory of the MPD data tree. Contains a tag cache,
-	  playlists and a music/ subdirectory that should contain (or
-          symlink to) your music collection.
-        '';
-      };
+          The directory where MPD stores its state, tag cache,
+          playlists etc.
+        ''; 
+      };  
 
-    };
+    };  
 
-  };
+  };  
 
 
   ###### implementation
 
-  config = mkIf config.services.mpd.enable {
-
-    environment.systemPackages = [ pkgs.mpd ];
-
-    users.extraUsers = singleton
-      { name = "mpd";
-        group = "mpd";
-        extraGroups = [ "audio" ];
-        description = "MPD system-wide daemon";
-        home = "${config.services.mpd.dataDir}";
-      };
-
-    users.extraGroups = singleton
-      { name = "mpd";
-        inherit gid;
-      };
-
-    jobs.mpd =
-      { description = "MPD system-wide server";
-
-        startOn = "startup";
-
-        preStart =
-          ''
-            mkdir -p /var/run/mpd && chown mpd /var/run/mpd
-            test -d ${config.services.mpd.dataDir} || \
-            ( mkdir -p --mode 755 ${config.services.mpd.dataDir}/music \
-                                  ${config.services.mpd.dataDir}/playlists && \
-              chown -R mpd:mpd ${config.services.mpd.dataDir} )
-          '';
-
-        daemonType = "fork";
-        exec =
-          ''
-            ${pkgs.mpd}/bin/mpd ${pkgs.writeText "mpd.conf" config.services.mpd.conffile}
-          '';
-      };
+  config = mkIf cfg.enable {
+
+    systemd.services.mpd = {
+      after = [ "network.target" "sound.target" ];
+      description = "Music Player Daemon";
+      wantedBy = [ "multi-user.target" ];
+      path = [ pkgs.mpd ];
+      script = "mpd --no-daemon ${mpdConf}";
+    };
+
+    users.extraUsers.mpd = {
+      inherit uid;
+      group = "mpd";
+      extraGroups = [ "audio" ];
+      description = "Music Player Daemon user";
+      home = "${cfg.dataDir}";
+    };
+
+    users.extraGroups.mpd.gid = gid;
 
   };