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

Changed files
+28 -11
nixos
modules
hardware
sensor
services
+10 -5
nixos/modules/hardware/sensor/hddtemp.nix
···
cfg = config.hardware.sensor.hddtemp;
-
wrapper = pkgs.writeShellScript "hddtemp-wrapper" ''
set -eEuo pipefail
file=/var/lib/hddtemp/hddtemp.db
-
drives=(${toString (map (e: ''$(realpath ${lib.escapeShellArg e}) '') cfg.drives)})
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} \
--daemon \
--unit=${cfg.unit} \
--file=$file \
-
''${drives[@]}
'';
in
···
description = "HDD/SSD temperature";
documentation = [ "man:hddtemp(8)" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "forking";
-
ExecStart = wrapper;
StateDirectory = "hddtemp";
PrivateTmp = true;
ProtectHome = "tmpfs";
···
cfg = config.hardware.sensor.hddtemp;
+
script = ''
set -eEuo pipefail
file=/var/lib/hddtemp/hddtemp.db
+
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}
+
${pkgs.hddtemp}/bin/hddtemp ${lib.escapeShellArgs cfg.extraArgs} \
--daemon \
--unit=${cfg.unit} \
--file=$file \
+
$drives
'';
in
···
description = "HDD/SSD temperature";
documentation = [ "man:hddtemp(8)" ];
wantedBy = [ "multi-user.target" ];
+
inherit script;
serviceConfig = {
Type = "forking";
StateDirectory = "hddtemp";
PrivateTmp = true;
ProtectHome = "tmpfs";
+18 -6
nixos/modules/services/hardware/hddfancontrol.nix
···
{
options = {
disks = lib.mkOption {
-
type = lib.types.listOf lib.types.path;
default = [ ];
description = ''
Drive(s) to get temperature from
'';
-
example = [ "/dev/sda" ];
};
pwmPaths = lib.mkOption {
-
type = lib.types.listOf lib.types.path;
default = [ ];
description = ''
PWM filepath(s) to control fan speed (under /sys), followed by initial and fan-stop PWM values
'';
-
example = [ "/sys/class/hwmon/hwmon2/pwm1:30:10" ];
};
logVerbosity = lib.mkOption {
···
documentation = [ "man:hddfancontrol(1)" ];
after = [ "hddtemp.service" ];
wants = [ "hddtemp.service" ];
serviceConfig = {
-
ExecStart = "${lib.getExe pkgs.hddfancontrol} -v ${cnf.logVerbosity} daemon ${lib.escapeShellArgs (args cnf)}";
-
CPUSchedulingPolicy = "rr";
CPUSchedulingPriority = 49;
···
{
options = {
disks = lib.mkOption {
+
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"
+
"`find /dev/disk/by-id -name \"scsi*\" -and -not -name \"*-part*\" -printf \"%p \"`"
+
];
};
pwmPaths = lib.mkOption {
+
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"
+
"`echo /sys/devices/platform/nct6775.656/hwmon/hwmon[[:print:]]`/pwm4:80:20"
+
];
};
logVerbosity = lib.mkOption {
···
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 = {
CPUSchedulingPolicy = "rr";
CPUSchedulingPriority = 49;