nixos/hddfancontrol: loosen pwmPaths and disks types to str, nixos/hddtemp: allow command substitution for drives (#421862)

This commit is contained in:
Benjamin Staffin
2025-09-28 15:24:20 +00:00
committed by GitHub
2 changed files with 28 additions and 11 deletions

View File

@@ -9,21 +9,26 @@ let
cfg = config.hardware.sensor.hddtemp;
wrapper = pkgs.writeShellScript "hddtemp-wrapper" ''
script = ''
set -eEuo pipefail
file=/var/lib/hddtemp/hddtemp.db
drives=(${toString (map (e: ''$(realpath ${lib.escapeShellArg e}) '') cfg.drives)})
raw_drives=""
${lib.concatStringsSep "\n" (map (drives: "raw_drives+=\"${drives} \"") cfg.drives)}
drives=""
for i in $raw_drives; do
drives+=" $(realpath $i)"
done
cp ${pkgs.hddtemp}/share/hddtemp/hddtemp.db $file
${lib.concatMapStringsSep "\n" (e: "echo ${lib.escapeShellArg e} >> $file") cfg.dbEntries}
exec ${pkgs.hddtemp}/bin/hddtemp ${lib.escapeShellArgs cfg.extraArgs} \
${pkgs.hddtemp}/bin/hddtemp ${lib.escapeShellArgs cfg.extraArgs} \
--daemon \
--unit=${cfg.unit} \
--file=$file \
''${drives[@]}
$drives
'';
in
@@ -77,9 +82,9 @@ in
description = "HDD/SSD temperature";
documentation = [ "man:hddtemp(8)" ];
wantedBy = [ "multi-user.target" ];
inherit script;
serviceConfig = {
Type = "forking";
ExecStart = wrapper;
StateDirectory = "hddtemp";
PrivateTmp = true;
ProtectHome = "tmpfs";

View File

@@ -52,21 +52,30 @@ in
{
options = {
disks = lib.mkOption {
type = lib.types.listOf lib.types.path;
type = lib.types.listOf lib.types.str;
default = [ ];
description = ''
Drive(s) to get temperature from
Can also use command substitution to automatically grab all matching drives; such as all scsi (sas) drives
'';
example = [ "/dev/sda" ];
example = [
"/dev/sda"
"`find /dev/disk/by-id -name \"scsi*\" -and -not -name \"*-part*\" -printf \"%p \"`"
];
};
pwmPaths = lib.mkOption {
type = lib.types.listOf lib.types.path;
type = lib.types.listOf lib.types.str;
default = [ ];
description = ''
PWM filepath(s) to control fan speed (under /sys), followed by initial and fan-stop PWM values
Can also use command substitution to ensure the correct hwmonX is selected on every boot
'';
example = [ "/sys/class/hwmon/hwmon2/pwm1:30:10" ];
example = [
"/sys/class/hwmon/hwmon2/pwm1:30:10"
"`echo /sys/devices/platform/nct6775.656/hwmon/hwmon[[:print:]]`/pwm4:80:20"
];
};
logVerbosity = lib.mkOption {
@@ -151,9 +160,12 @@ in
documentation = [ "man:hddfancontrol(1)" ];
after = [ "hddtemp.service" ];
wants = [ "hddtemp.service" ];
script =
let
argString = lib.strings.concatStringsSep " " (args cnf);
in
"${lib.getExe pkgs.hddfancontrol} -v ${cnf.logVerbosity} daemon ${argString}";
serviceConfig = {
ExecStart = "${lib.getExe pkgs.hddfancontrol} -v ${cnf.logVerbosity} daemon ${lib.escapeShellArgs (args cnf)}";
CPUSchedulingPolicy = "rr";
CPUSchedulingPriority = 49;