2018-07-20 22:56:59 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
2016-04-23 15:49:33 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.emby;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.emby = {
|
|
|
|
enable = mkEnableOption "Emby Media Server";
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "emby";
|
|
|
|
description = "User account under which Emby runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "emby";
|
|
|
|
description = "Group under which emby runs.";
|
|
|
|
};
|
2017-05-12 22:01:25 +02:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/emby/ProgramData-Server";
|
|
|
|
description = "Location where Emby stores its data.";
|
|
|
|
};
|
2016-04-23 15:49:33 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.emby = {
|
|
|
|
description = "Emby Media Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
2018-09-20 12:35:51 +02:00
|
|
|
if [ -d ${cfg.dataDir} ]
|
|
|
|
then
|
|
|
|
for plugin in ${cfg.dataDir}/plugins/*
|
|
|
|
do
|
|
|
|
echo "Correcting permissions of plugin: $plugin"
|
|
|
|
chmod u+w $plugin
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "Creating initial Emby data directory in ${cfg.dataDir}"
|
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}
|
|
|
|
fi
|
2016-04-23 15:49:33 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PermissionsStartOnly = "true";
|
2018-10-08 14:10:00 +02:00
|
|
|
ExecStart = "${pkgs.emby}/bin/emby -programdata ${cfg.dataDir}";
|
2016-04-23 15:49:33 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users = mkIf (cfg.user == "emby") {
|
2016-04-23 15:49:33 +02:00
|
|
|
emby = {
|
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.emby;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups = mkIf (cfg.group == "emby") {
|
2016-04-23 15:49:33 +02:00
|
|
|
emby = {
|
|
|
|
gid = config.ids.gids.emby;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|