2018-01-19 12:44:14 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.serviio;
|
|
|
|
|
|
|
|
serviioStart = pkgs.writeScript "serviio.sh" ''
|
|
|
|
#!${pkgs.bash}/bin/sh
|
|
|
|
|
|
|
|
SERVIIO_HOME=${pkgs.serviio}
|
2019-09-01 01:07:23 +00:00
|
|
|
|
2018-01-19 12:44:14 +00:00
|
|
|
# Setup the classpath
|
|
|
|
SERVIIO_CLASS_PATH="$SERVIIO_HOME/lib/*:$SERVIIO_HOME/config"
|
|
|
|
|
|
|
|
# Setup Serviio specific properties
|
|
|
|
JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dorg.restlet.engine.loggerFacadeClass=org.restlet.ext.slf4j.Slf4jLoggerFacade
|
|
|
|
-Dderby.system.home=${cfg.dataDir}/library -Dserviio.home=${cfg.dataDir} -Dffmpeg.location=${pkgs.ffmpeg}/bin/ffmpeg -Ddcraw.location=${pkgs.dcraw}/bin/dcraw"
|
|
|
|
|
|
|
|
# Execute the JVM in the foreground
|
|
|
|
exec ${pkgs.jre}/bin/java -Xmx512M -Xms20M -XX:+UseG1GC -XX:GCTimeRatio=1 -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 $JAVA_OPTS -classpath "$SERVIIO_CLASS_PATH" org.serviio.MediaServer "$@"
|
|
|
|
'';
|
2019-09-01 01:07:23 +00:00
|
|
|
|
2018-01-19 12:44:14 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.serviio = {
|
2019-09-01 01:07:23 +00:00
|
|
|
|
2018-01-19 12:44:14 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-01-19 12:44:14 +00:00
|
|
|
Whether to enable the Serviio Media Server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/serviio";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-01-19 12:44:14 +00:00
|
|
|
The directory where serviio stores its state, data, etc.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.serviio = {
|
|
|
|
description = "Serviio Media Server";
|
2019-09-01 01:07:23 +00:00
|
|
|
after = [ "network.target" ];
|
2018-01-19 12:44:14 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.serviio ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "serviio";
|
|
|
|
Group = "serviio";
|
|
|
|
ExecStart = "${serviioStart}";
|
|
|
|
ExecStop = "${serviioStart} -stop";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.serviio =
|
|
|
|
{ group = "serviio";
|
2018-01-19 12:44:14 +00:00
|
|
|
home = cfg.dataDir;
|
|
|
|
description = "Serviio Media Server User";
|
|
|
|
createHome = true;
|
|
|
|
isSystemUser = true;
|
2019-09-14 17:51:29 +00:00
|
|
|
};
|
2018-01-19 12:44:14 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups.serviio = { };
|
2018-01-19 12:44:14 +00:00
|
|
|
|
|
|
|
networking.firewall = {
|
2019-09-01 01:07:23 +00:00
|
|
|
allowedTCPPorts = [
|
2018-01-19 12:44:14 +00:00
|
|
|
8895 # serve UPnP responses
|
|
|
|
23423 # console
|
|
|
|
23424 # mediabrowser
|
|
|
|
];
|
2019-09-01 01:07:23 +00:00
|
|
|
allowedUDPPorts = [
|
2022-12-18 00:31:14 +00:00
|
|
|
1900 # UPnP service discovery
|
2018-01-19 12:44:14 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|