1 { config, lib, pkgs, ... }:
6 cfg = config.services.hqplayerd;
8 # XXX: This is hard-coded in the distributed binary, don't try to change it.
9 stateDir = "/var/lib/hqplayer";
10 configDir = "/etc/hqplayer";
14 services.hqplayerd = {
15 enable = mkEnableOption (lib.mdDoc "HQPlayer Embedded");
19 type = types.nullOr types.str;
21 description = lib.mdDoc ''
22 Username used for HQPlayer's WebUI.
24 Without this you will need to manually create the credentials after
25 first start by going to http://your.ip/8088/auth
30 type = types.nullOr types.str;
32 description = lib.mdDoc ''
33 Password used for HQPlayer's WebUI.
35 Without this you will need to manually create the credentials after
36 first start by going to http://your.ip/8088/auth
41 licenseFile = mkOption {
42 type = types.nullOr types.path;
44 description = lib.mdDoc ''
45 Path to the HQPlayer license key file.
47 Without this, the service will run in trial mode and restart every 30
52 openFirewall = mkOption {
55 description = lib.mdDoc ''
56 Opens ports needed for the WebUI and controller API.
61 type = types.nullOr types.lines;
63 description = lib.mdDoc ''
64 HQplayer daemon configuration, written to /etc/hqplayer/hqplayerd.xml.
66 Refer to share/doc/hqplayerd/readme.txt in the hqplayerd derivation for possible values.
72 config = mkIf cfg.enable {
75 assertion = (cfg.auth.username != null -> cfg.auth.password != null)
76 && (cfg.auth.password != null -> cfg.auth.username != null);
77 message = "You must set either both services.hqplayer.auth.username and password, or neither.";
83 "hqplayer/hqplayerd.xml" = mkIf (cfg.config != null) { source = pkgs.writeText "hqplayerd.xml" cfg.config; };
84 "hqplayer/hqplayerd4-key.xml" = mkIf (cfg.licenseFile != null) { source = cfg.licenseFile; };
85 "modules-load.d/taudio2.conf".source = "${pkg}/etc/modules-load.d/taudio2.conf";
87 systemPackages = [ pkg ];
90 networking.firewall = mkIf cfg.openFirewall {
91 allowedTCPPorts = [ 8088 4321 ];
94 services.udev.packages = [ pkg ];
98 "d ${configDir} 0755 hqplayer hqplayer - -"
99 "d ${stateDir} 0755 hqplayer hqplayer - -"
100 "d ${stateDir}/home 0755 hqplayer hqplayer - -"
105 services.hqplayerd = {
106 wantedBy = [ "multi-user.target" ];
107 after = [ "systemd-tmpfiles-setup.service" ];
109 environment.HOME = "${stateDir}/home";
111 unitConfig.ConditionPathExists = [ configDir stateDir ];
113 restartTriggers = optionals (cfg.config != null) [ config.environment.etc."hqplayer/hqplayerd.xml".source ];
116 cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}"
117 chmod -R u+wX "${stateDir}/web"
119 if [ ! -f "${configDir}/hqplayerd.xml" ]; then
120 echo "creating initial config file"
121 install -m 0644 "${pkg}/etc/hqplayer/hqplayerd.xml" "${configDir}/hqplayerd.xml"
123 '' + optionalString (cfg.auth.username != null && cfg.auth.password != null) ''
124 ${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password}
130 hqplayer.gid = config.ids.gids.hqplayer;
135 description = "hqplayer daemon user";
136 extraGroups = [ "audio" "video" ];
138 uid = config.ids.uids.hqplayer;