at 23.11-pre 4.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.hqplayerd; 7 pkg = pkgs.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"; 11in 12{ 13 options = { 14 services.hqplayerd = { 15 enable = mkEnableOption (lib.mdDoc "HQPlayer Embedded"); 16 17 auth = { 18 username = mkOption { 19 type = types.nullOr types.str; 20 default = null; 21 description = lib.mdDoc '' 22 Username used for HQPlayer's WebUI. 23 24 Without this you will need to manually create the credentials after 25 first start by going to http://your.ip/8088/auth 26 ''; 27 }; 28 29 password = mkOption { 30 type = types.nullOr types.str; 31 default = null; 32 description = lib.mdDoc '' 33 Password used for HQPlayer's WebUI. 34 35 Without this you will need to manually create the credentials after 36 first start by going to http://your.ip/8088/auth 37 ''; 38 }; 39 }; 40 41 licenseFile = mkOption { 42 type = types.nullOr types.path; 43 default = null; 44 description = lib.mdDoc '' 45 Path to the HQPlayer license key file. 46 47 Without this, the service will run in trial mode and restart every 30 48 minutes. 49 ''; 50 }; 51 52 openFirewall = mkOption { 53 type = types.bool; 54 default = false; 55 description = lib.mdDoc '' 56 Opens ports needed for the WebUI and controller API. 57 ''; 58 }; 59 60 config = mkOption { 61 type = types.nullOr types.lines; 62 default = null; 63 description = lib.mdDoc '' 64 HQplayer daemon configuration, written to /etc/hqplayer/hqplayerd.xml. 65 66 Refer to share/doc/hqplayerd/readme.txt in the hqplayerd derivation for possible values. 67 ''; 68 }; 69 }; 70 }; 71 72 config = mkIf cfg.enable { 73 assertions = [ 74 { 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."; 78 } 79 ]; 80 81 environment = { 82 etc = { 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 }; 86 systemPackages = [ pkg ]; 87 }; 88 89 networking.firewall = mkIf cfg.openFirewall { 90 allowedTCPPorts = [ 8088 4321 ]; 91 }; 92 93 systemd = { 94 tmpfiles.rules = [ 95 "d ${configDir} 0755 hqplayer hqplayer - -" 96 "d ${stateDir} 0755 hqplayer hqplayer - -" 97 "d ${stateDir}/home 0755 hqplayer hqplayer - -" 98 ]; 99 100 packages = [ pkg ]; 101 102 services.hqplayerd = { 103 wantedBy = [ "multi-user.target" ]; 104 after = [ "systemd-tmpfiles-setup.service" ]; 105 106 environment.HOME = "${stateDir}/home"; 107 108 unitConfig.ConditionPathExists = [ configDir stateDir ]; 109 110 restartTriggers = optionals (cfg.config != null) [ config.environment.etc."hqplayer/hqplayerd.xml".source ]; 111 112 preStart = '' 113 cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}" 114 chmod -R u+wX "${stateDir}/web" 115 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" 119 fi 120 '' + optionalString (cfg.auth.username != null && cfg.auth.password != null) '' 121 ${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password} 122 ''; 123 }; 124 }; 125 126 users.groups = { 127 hqplayer.gid = config.ids.gids.hqplayer; 128 }; 129 130 users.users = { 131 hqplayer = { 132 description = "hqplayer daemon user"; 133 extraGroups = [ "audio" "video" ]; 134 group = "hqplayer"; 135 uid = config.ids.uids.hqplayer; 136 }; 137 }; 138 }; 139}