2014-07-28 19:52:32 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
uid = config.ids.uids.mopidy;
|
|
|
|
gid = config.ids.gids.mopidy;
|
|
|
|
cfg = config.services.mopidy;
|
|
|
|
|
|
|
|
mopidyConf = writeText "mopidy.conf" cfg.configuration;
|
|
|
|
|
2018-01-08 15:32:36 +01:00
|
|
|
mopidyEnv = buildEnv {
|
|
|
|
name = "mopidy-with-extensions-${mopidy.version}";
|
|
|
|
paths = closePropagation cfg.extensionPackages;
|
|
|
|
pathsToLink = [ "/${python.sitePackages}" ];
|
|
|
|
buildInputs = [ makeWrapper ];
|
|
|
|
postBuild = ''
|
|
|
|
makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \
|
|
|
|
--prefix PYTHONPATH : $out/${python.sitePackages}
|
|
|
|
'';
|
2014-07-28 19:52:32 +02:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mopidy = {
|
|
|
|
|
2016-09-12 04:47:08 +02:00
|
|
|
enable = mkEnableOption "Mopidy, a music player daemon";
|
2014-07-28 19:52:32 +02:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/mopidy";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The directory where Mopidy stores its state.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extensionPackages = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.package;
|
2014-08-27 23:41:15 +02:00
|
|
|
example = literalExample "[ pkgs.mopidy-spotify ]";
|
2014-07-28 19:52:32 +02:00
|
|
|
description = ''
|
|
|
|
Mopidy extensions that should be loaded by the service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configuration = mkOption {
|
2016-07-31 18:35:09 +02:00
|
|
|
default = "";
|
2014-07-28 19:52:32 +02:00
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
The configuration that Mopidy should use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigFiles = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
Extra config file read by Mopidy when the service starts.
|
|
|
|
Later files in the list overrides earlier configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.mopidy = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" "sound.target" ];
|
|
|
|
description = "mopidy music player daemon";
|
|
|
|
preStart = "mkdir -p ${cfg.dataDir} && chown -R mopidy:mopidy ${cfg.dataDir}";
|
|
|
|
serviceConfig = {
|
2015-12-16 04:31:42 +01:00
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
|
2014-07-28 19:52:32 +02:00
|
|
|
User = "mopidy";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-12 01:40:44 +02:00
|
|
|
systemd.services.mopidy-scan = {
|
|
|
|
description = "mopidy local files scanner";
|
|
|
|
preStart = "mkdir -p ${cfg.dataDir} && chown -R mopidy:mopidy ${cfg.dataDir}";
|
|
|
|
serviceConfig = {
|
2015-12-16 04:31:42 +01:00
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
|
2014-08-12 01:40:44 +02:00
|
|
|
User = "mopidy";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-07-28 19:52:32 +02:00
|
|
|
users.extraUsers.mopidy = {
|
|
|
|
inherit uid;
|
|
|
|
group = "mopidy";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "Mopidy daemon user";
|
|
|
|
home = "${cfg.dataDir}";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.mopidy.gid = gid;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|