2021-06-13 23:59:13 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.hqplayerd;
|
|
|
|
pkg = pkgs.hqplayerd;
|
|
|
|
# XXX: This is hard-coded in the distributed binary, don't try to change it.
|
|
|
|
stateDir = "/var/lib/hqplayer";
|
|
|
|
configDir = "/etc/hqplayer";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.hqplayerd = {
|
|
|
|
enable = mkEnableOption "HQPlayer Embedded";
|
|
|
|
|
|
|
|
licenseFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to the HQPlayer license key file.
|
|
|
|
|
|
|
|
Without this, the service will run in trial mode and restart every 30
|
|
|
|
minutes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
auth = {
|
|
|
|
username = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Username used for HQPlayer's WebUI.
|
|
|
|
|
|
|
|
Without this you will need to manually create the credentials after
|
|
|
|
first start by going to http://your.ip/8088/auth
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Password used for HQPlayer's WebUI.
|
|
|
|
|
|
|
|
Without this you will need to manually create the credentials after
|
|
|
|
first start by going to http://your.ip/8088/auth
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Open TCP port 8088 in the firewall for the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = (cfg.auth.username != null -> cfg.auth.password != null)
|
|
|
|
&& (cfg.auth.password != null -> cfg.auth.username != null);
|
|
|
|
message = "You must set either both services.hqplayer.auth.username and password, or neither.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
etc = {
|
|
|
|
"hqplayer/hqplayerd4-key.xml" = mkIf (cfg.licenseFile != null) { source = cfg.licenseFile; };
|
|
|
|
"modules-load.d/taudio2.conf".source = "${pkg}/etc/modules-load.d/taudio2.conf";
|
|
|
|
};
|
|
|
|
systemPackages = [ pkg ];
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 8088 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.udev.packages = [ pkg ];
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
tmpfiles.rules = [
|
2021-08-04 18:55:12 +01:00
|
|
|
"d ${configDir} 0755 hqplayer hqplayer - -"
|
|
|
|
"d ${stateDir} 0755 hqplayer hqplayer - -"
|
|
|
|
"d ${stateDir}/home 0755 hqplayer hqplayer - -"
|
2021-06-13 23:59:13 +01:00
|
|
|
];
|
|
|
|
|
2021-08-04 18:56:11 +01:00
|
|
|
packages = [ pkg ];
|
|
|
|
|
2021-06-13 23:59:13 +01:00
|
|
|
services.hqplayerd = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-08-04 18:56:11 +01:00
|
|
|
after = [ "systemd-tmpfiles-setup.service" ];
|
2021-06-13 23:59:13 +01:00
|
|
|
|
2021-08-04 07:29:31 +01:00
|
|
|
environment.HOME = "${stateDir}/home";
|
|
|
|
|
2021-06-13 23:59:13 +01:00
|
|
|
unitConfig.ConditionPathExists = [ configDir stateDir ];
|
|
|
|
|
2021-08-04 18:20:36 +01:00
|
|
|
preStart = ''
|
|
|
|
cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}"
|
|
|
|
chmod -R u+wX "${stateDir}/web"
|
|
|
|
|
|
|
|
if [ ! -f "${configDir}/hqplayerd.xml" ]; then
|
|
|
|
echo "creating initial config file"
|
|
|
|
install -m 0644 "${pkg}/etc/hqplayer/hqplayerd.xml" "${configDir}/hqplayerd.xml"
|
|
|
|
fi
|
|
|
|
'' + optionalString (cfg.auth.username != null && cfg.auth.password != null) ''
|
|
|
|
${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password}
|
|
|
|
'';
|
2021-06-13 23:59:13 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-08-04 18:55:12 +01:00
|
|
|
users.groups = {
|
2021-06-13 23:59:13 +01:00
|
|
|
hqplayer.gid = config.ids.gids.hqplayer;
|
|
|
|
};
|
|
|
|
|
2021-08-04 18:55:12 +01:00
|
|
|
users.users = {
|
2021-06-13 23:59:13 +01:00
|
|
|
hqplayer = {
|
|
|
|
description = "hqplayer daemon user";
|
|
|
|
extraGroups = [ "audio" ];
|
2021-08-04 18:55:12 +01:00
|
|
|
group = "hqplayer";
|
2021-06-13 23:59:13 +01:00
|
|
|
uid = config.ids.uids.hqplayer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|