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 "HQPlayer Embedded";
19 type = types.nullOr types.str;
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;
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;
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 {
56 Opens ports needed for the WebUI and controller API.
61 type = types.nullOr types.lines;
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; };
86 systemPackages = [ pkg ];
89 networking.firewall = mkIf cfg.openFirewall {
90 allowedTCPPorts = [ 8088 4321 ];
95 "d ${configDir} 0755 hqplayer hqplayer - -"
96 "d ${stateDir} 0755 hqplayer hqplayer - -"
97 "d ${stateDir}/home 0755 hqplayer hqplayer - -"
102 services.hqplayerd = {
103 wantedBy = [ "multi-user.target" ];
104 after = [ "systemd-tmpfiles-setup.service" ];
106 environment.HOME = "${stateDir}/home";
108 unitConfig.ConditionPathExists = [ configDir stateDir ];
110 restartTriggers = optionals (cfg.config != null) [ config.environment.etc."hqplayer/hqplayerd.xml".source ];
113 cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}"
114 chmod -R u+wX "${stateDir}/web"
116 if [ ! -f "${configDir}/hqplayerd.xml" ]; then
117 echo "creating initial config file"
118 install -m 0644 "${pkg}/etc/hqplayer/hqplayerd.xml" "${configDir}/hqplayerd.xml"
120 '' + optionalString (cfg.auth.username != null && cfg.auth.password != null) ''
121 ${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password}
127 hqplayer.gid = config.ids.gids.hqplayer;
132 description = "hqplayer daemon user";
133 extraGroups = [ "audio" "video" ];
135 uid = config.ids.uids.hqplayer;