2014-07-28 18:52:32 +01: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 14:32:36 +00: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 18:52:32 +01:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mopidy = {
|
|
|
|
|
2016-09-12 03:47:08 +01:00
|
|
|
enable = mkEnableOption "Mopidy, a music player daemon";
|
2014-07-28 18:52:32 +01: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 22:41:15 +01:00
|
|
|
example = literalExample "[ pkgs.mopidy-spotify ]";
|
2014-07-28 18:52:32 +01:00
|
|
|
description = ''
|
|
|
|
Mopidy extensions that should be loaded by the service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configuration = mkOption {
|
2016-07-31 17:35:09 +01:00
|
|
|
default = "";
|
2014-07-28 18:52:32 +01: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 {
|
|
|
|
|
2019-02-23 21:15:58 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' - mopidy mopidy - -"
|
|
|
|
];
|
|
|
|
|
2014-07-28 18:52:32 +01:00
|
|
|
systemd.services.mopidy = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" "sound.target" ];
|
|
|
|
description = "mopidy music player daemon";
|
|
|
|
serviceConfig = {
|
2015-12-16 03:31:42 +00:00
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
|
2014-07-28 18:52:32 +01:00
|
|
|
User = "mopidy";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-12 00:40:44 +01:00
|
|
|
systemd.services.mopidy-scan = {
|
|
|
|
description = "mopidy local files scanner";
|
|
|
|
serviceConfig = {
|
2015-12-16 03:31:42 +00:00
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
|
2014-08-12 00:40:44 +01:00
|
|
|
User = "mopidy";
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.mopidy = {
|
2014-07-28 18:52:32 +01:00
|
|
|
inherit uid;
|
|
|
|
group = "mopidy";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "Mopidy daemon user";
|
2019-02-23 21:15:58 +00:00
|
|
|
home = cfg.dataDir;
|
2014-07-28 18:52:32 +01:00
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.mopidy.gid = gid;
|
2014-07-28 18:52:32 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|