2020-04-24 23:36:52 +00: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;
|
|
|
|
|
|
|
|
mopidyEnv = buildEnv {
|
|
|
|
name = "mopidy-with-extensions-${mopidy.version}";
|
|
|
|
paths = closePropagation cfg.extensionPackages;
|
|
|
|
pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ];
|
2022-10-21 18:38:19 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
postBuild = ''
|
|
|
|
makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \
|
|
|
|
--prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mopidy = {
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "Mopidy, a music player daemon";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/mopidy";
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The directory where Mopidy stores its state.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extensionPackages = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.package;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "[ pkgs.mopidy-spotify ]";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Mopidy extensions that should be loaded by the service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configuration = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The configuration that Mopidy should use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigFiles = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra config file read by Mopidy when the service starts.
|
|
|
|
Later files in the list overrides earlier configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2024-02-07 01:22:34 +00:00
|
|
|
systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = {
|
|
|
|
user = "mopidy";
|
|
|
|
group = "mopidy";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.mopidy = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-01-02 11:29:13 +00:00
|
|
|
after = [ "network-online.target" "sound.target" ];
|
2024-06-05 15:53:02 +00:00
|
|
|
wants = [ "network-online.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "mopidy music player daemon";
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
|
|
|
|
User = "mopidy";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.mopidy-scan = {
|
|
|
|
description = "mopidy local files scanner";
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
|
|
|
|
User = "mopidy";
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.mopidy = {
|
|
|
|
inherit uid;
|
|
|
|
group = "mopidy";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "Mopidy daemon user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.mopidy.gid = gid;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|