at 24.11-pre 1.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.services.hddfancontrol; 5 types = lib.types; 6in 7 8{ 9 options = { 10 11 services.hddfancontrol.enable = lib.mkEnableOption "hddfancontrol daemon"; 12 13 services.hddfancontrol.disks = lib.mkOption { 14 type = with types; listOf path; 15 default = []; 16 description = '' 17 Drive(s) to get temperature from 18 ''; 19 example = ["/dev/sda"]; 20 }; 21 22 services.hddfancontrol.pwmPaths = lib.mkOption { 23 type = with types; listOf path; 24 default = []; 25 description = '' 26 PWM filepath(s) to control fan speed (under /sys) 27 ''; 28 example = ["/sys/class/hwmon/hwmon2/pwm1"]; 29 }; 30 31 services.hddfancontrol.smartctl = lib.mkOption { 32 type = types.bool; 33 default = false; 34 description = '' 35 Probe temperature using smartctl instead of hddtemp or hdparm 36 ''; 37 }; 38 39 services.hddfancontrol.extraArgs = lib.mkOption { 40 type = with types; listOf str; 41 default = []; 42 description = '' 43 Extra commandline arguments for hddfancontrol 44 ''; 45 example = ["--pwm-start-value=32" 46 "--pwm-stop-value=0" 47 "--spin-down-time=900"]; 48 }; 49 }; 50 51 config = lib.mkIf cfg.enable ( 52 let args = lib.concatLists [ 53 ["-d"] cfg.disks 54 ["-p"] cfg.pwmPaths 55 (lib.optional cfg.smartctl "--smartctl") 56 cfg.extraArgs 57 ]; in { 58 systemd.packages = [pkgs.hddfancontrol]; 59 60 systemd.services.hddfancontrol = { 61 wantedBy = [ "multi-user.target" ]; 62 environment.HDDFANCONTROL_ARGS = lib.escapeShellArgs args; 63 serviceConfig = { 64 # Hardening 65 PrivateNetwork = true; 66 }; 67 }; 68 } 69 ); 70}