From a6899457c31d021d9caa27231a0a61f1b9199c0c Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 4 Aug 2021 10:18:24 -0700 Subject: [PATCH 1/5] hqplayerd: install main configuration file While packaging I had missed this in the file listing, and ended up having to add a hack to the NixOS module to create an empty configuration file. Turns out that wasn't needed at all, as long as we distribute the real configuration file with the package, which this change does. --- pkgs/servers/hqplayerd/default.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/servers/hqplayerd/default.nix b/pkgs/servers/hqplayerd/default.nix index 76f8bde3e4ed..8315f17dec02 100644 --- a/pkgs/servers/hqplayerd/default.nix +++ b/pkgs/servers/hqplayerd/default.nix @@ -53,25 +53,29 @@ stdenv.mkDerivation rec { mkdir -p $out/bin cp ./usr/bin/hqplayerd $out/bin + # main configuration + mkdir -p $out/etc/hqplayer + cp ./etc/hqplayer/hqplayerd.xml $out/etc/hqplayer/ + # udev rules mkdir -p $out/etc/udev/rules.d - cp ./etc/udev/rules.d/50-taudio2.rules $out/etc/udev/rules.d + cp ./etc/udev/rules.d/50-taudio2.rules $out/etc/udev/rules.d/ # kernel module cfgs mkdir -p $out/etc/modules-load.d - cp ./etc/modules-load.d/taudio2.conf $out/etc/modules-load.d + cp ./etc/modules-load.d/taudio2.conf $out/etc/modules-load.d/ # systemd service file mkdir -p $out/lib/systemd/system - cp ./usr/lib/systemd/system/hqplayerd.service $out/lib/systemd/system + cp ./usr/lib/systemd/system/hqplayerd.service $out/lib/systemd/system/ # documentation mkdir -p $out/share/doc/hqplayerd - cp ./usr/share/doc/hqplayerd/* $out/share/doc/hqplayerd + cp ./usr/share/doc/hqplayerd/* $out/share/doc/hqplayerd/ # misc service support files mkdir -p $out/var/lib/hqplayer - cp -r ./var/lib/hqplayer/web $out/var/lib/hqplayer/web + cp -r ./var/lib/hqplayer/web $out/var/lib/hqplayer runHook postInstall ''; From ade8623d559efc68b0fe399d4b3211aa4d71a7ab Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 4 Aug 2021 11:27:02 -0700 Subject: [PATCH 2/5] hqplayerd: patch out NetworkManager unit requirement --- pkgs/servers/hqplayerd/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/servers/hqplayerd/default.nix b/pkgs/servers/hqplayerd/default.nix index 8315f17dec02..14fe83ea5cb3 100644 --- a/pkgs/servers/hqplayerd/default.nix +++ b/pkgs/servers/hqplayerd/default.nix @@ -82,7 +82,8 @@ stdenv.mkDerivation rec { postInstall = '' substituteInPlace $out/lib/systemd/system/hqplayerd.service \ - --replace /usr/bin/hqplayerd $out/bin/hqplayerd + --replace /usr/bin/hqplayerd $out/bin/hqplayerd \ + --replace "NetworkManager-wait-online.service" "" ''; postFixup = '' From 3ccb633f85a6d1e7931e47206a85773ed9a67383 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 4 Aug 2021 10:20:36 -0700 Subject: [PATCH 3/5] nixos/hqplayerd: use package-provided config file instead of blank --- nixos/modules/services/audio/hqplayerd.nix | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/nixos/modules/services/audio/hqplayerd.nix b/nixos/modules/services/audio/hqplayerd.nix index b4d8468a2375..7d221e5b6dea 100644 --- a/nixos/modules/services/audio/hqplayerd.nix +++ b/nixos/modules/services/audio/hqplayerd.nix @@ -115,25 +115,17 @@ in unitConfig.ConditionPathExists = [ configDir stateDir ]; - preStart = - let - blankCfg = pkgs.writeText "hqplayerd.xml" '' - - - - ''; - in - '' - cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}" - chmod -R u+wX "${stateDir}/web" + preStart = '' + cp -r "${pkg}/var/lib/hqplayer/web" "${stateDir}" + chmod -R u+wX "${stateDir}/web" - if [ ! -f "${configDir}/hqplayerd.xml" ]; then - echo "creating blank config file" - install -m 0644 "${blankCfg}" "${configDir}/hqplayerd.xml" - fi - '' + optionalString (cfg.auth.username != null && cfg.auth.password != null) '' - ${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password} - ''; + 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} + ''; serviceConfig = { ExecStart = "${pkg}/bin/hqplayerd"; From e2426336691d27cc926f30e1b8f9114ebe4e911b Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 4 Aug 2021 10:55:12 -0700 Subject: [PATCH 4/5] nixos/hqplayerd: remove configurable user/group The service is adamant that it must run under the right user, so let's just enforce it. --- nixos/modules/services/audio/hqplayerd.nix | 32 ++++++---------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/nixos/modules/services/audio/hqplayerd.nix b/nixos/modules/services/audio/hqplayerd.nix index 7d221e5b6dea..be1d48494857 100644 --- a/nixos/modules/services/audio/hqplayerd.nix +++ b/nixos/modules/services/audio/hqplayerd.nix @@ -56,22 +56,6 @@ in Open TCP port 8088 in the firewall for the server. ''; }; - - user = mkOption { - type = types.str; - default = "hqplayer"; - description = '' - User account under which hqplayerd runs. - ''; - }; - - group = mkOption { - type = types.str; - default = "hqplayer"; - description = '' - Group account under which hqplayerd runs. - ''; - }; }; }; @@ -100,9 +84,9 @@ in systemd = { tmpfiles.rules = [ - "d ${configDir} 0755 ${cfg.user} ${cfg.group} - -" - "d ${stateDir} 0755 ${cfg.user} ${cfg.group} - -" - "d ${stateDir}/home 0755 ${cfg.user} ${cfg.group} - -" + "d ${configDir} 0755 hqplayer hqplayer - -" + "d ${stateDir} 0755 hqplayer hqplayer - -" + "d ${stateDir}/home 0755 hqplayer hqplayer - -" ]; services.hqplayerd = { @@ -130,8 +114,8 @@ in serviceConfig = { ExecStart = "${pkg}/bin/hqplayerd"; - User = cfg.user; - Group = cfg.group; + User = "hqplayer"; + Group = "hqplayer"; Restart = "on-failure"; RestartSec = 5; @@ -145,15 +129,15 @@ in }; }; - users.groups = mkIf (cfg.group == "hqplayer") { + users.groups = { hqplayer.gid = config.ids.gids.hqplayer; }; - users.users = mkIf (cfg.user == "hqplayer") { + users.users = { hqplayer = { description = "hqplayer daemon user"; extraGroups = [ "audio" ]; - group = cfg.group; + group = "hqplayer"; uid = config.ids.uids.hqplayer; }; }; From 1df5e3cdf383dbfa9868b00f4b157dc6253efa22 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 4 Aug 2021 10:56:11 -0700 Subject: [PATCH 5/5] nixos/hqplayerd: use upstream unit as much as possible --- nixos/modules/services/audio/hqplayerd.nix | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/nixos/modules/services/audio/hqplayerd.nix b/nixos/modules/services/audio/hqplayerd.nix index be1d48494857..6eeaffce1b15 100644 --- a/nixos/modules/services/audio/hqplayerd.nix +++ b/nixos/modules/services/audio/hqplayerd.nix @@ -89,11 +89,11 @@ in "d ${stateDir}/home 0755 hqplayer hqplayer - -" ]; + packages = [ pkg ]; + services.hqplayerd = { - description = "HQPlayer daemon"; wantedBy = [ "multi-user.target" ]; - requires = [ "network-online.target" "sound.target" "systemd-udev-settle.service" ]; - after = [ "network-online.target" "sound.target" "systemd-udev-settle.service" "local-fs.target" "remote-fs.target" "systemd-tmpfiles-setup.service" ]; + after = [ "systemd-tmpfiles-setup.service" ]; environment.HOME = "${stateDir}/home"; @@ -110,22 +110,6 @@ in '' + optionalString (cfg.auth.username != null && cfg.auth.password != null) '' ${pkg}/bin/hqplayerd -s ${cfg.auth.username} ${cfg.auth.password} ''; - - serviceConfig = { - ExecStart = "${pkg}/bin/hqplayerd"; - - User = "hqplayer"; - Group = "hqplayer"; - - Restart = "on-failure"; - RestartSec = 5; - - Nice = -10; - IOSchedulingClass = "realtime"; - LimitMEMLOCK = "1G"; - LimitNICE = -10; - LimitRTPRIO = 98; - }; }; };