1 { config, lib, pkgs, ... }:
7 uid = config.ids.uids.mopidy;
8 gid = config.ids.gids.mopidy;
9 cfg = config.services.mopidy;
11 mopidyConf = writeText "mopidy.conf" cfg.configuration;
13 mopidyEnv = buildEnv {
14 name = "mopidy-with-extensions-${mopidy.version}";
15 paths = closePropagation cfg.extensionPackages;
16 pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ];
17 nativeBuildInputs = [ makeWrapper ];
19 makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \
20 --prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages}
29 enable = mkEnableOption (lib.mdDoc "Mopidy, a music player daemon");
32 default = "/var/lib/mopidy";
34 description = lib.mdDoc ''
35 The directory where Mopidy stores its state.
39 extensionPackages = mkOption {
41 type = types.listOf types.package;
42 example = literalExpression "[ pkgs.mopidy-spotify ]";
43 description = lib.mdDoc ''
44 Mopidy extensions that should be loaded by the service.
48 configuration = mkOption {
51 description = lib.mdDoc ''
52 The configuration that Mopidy should use.
56 extraConfigFiles = mkOption {
58 type = types.listOf types.str;
59 description = lib.mdDoc ''
60 Extra config file read by Mopidy when the service starts.
61 Later files in the list overrides earlier configuration.
71 config = mkIf cfg.enable {
73 systemd.tmpfiles.rules = [
74 "d '${cfg.dataDir}' - mopidy mopidy - -"
77 systemd.services.mopidy = {
78 wantedBy = [ "multi-user.target" ];
79 after = [ "network.target" "sound.target" ];
80 description = "mopidy music player daemon";
82 ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
87 systemd.services.mopidy-scan = {
88 description = "mopidy local files scanner";
90 ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
96 users.users.mopidy = {
99 extraGroups = [ "audio" ];
100 description = "Mopidy daemon user";
104 users.groups.mopidy.gid = gid;