forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NixOS#239801 from benley/hddfancontrol
hddfancontrol: init at 1.5.1 (plus nixos module)
- Loading branch information
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
cfg = config.services.hddfancontrol; | ||
types = lib.types; | ||
in | ||
|
||
{ | ||
options = { | ||
|
||
services.hddfancontrol.enable = lib.mkEnableOption "hddfancontrol daemon"; | ||
|
||
services.hddfancontrol.disks = lib.mkOption { | ||
type = with types; listOf path; | ||
default = []; | ||
description = lib.mdDoc '' | ||
Drive(s) to get temperature from | ||
''; | ||
example = ["/dev/sda"]; | ||
}; | ||
|
||
services.hddfancontrol.pwmPaths = lib.mkOption { | ||
type = with types; listOf path; | ||
default = []; | ||
description = lib.mdDoc '' | ||
PWM filepath(s) to control fan speed (under /sys) | ||
''; | ||
example = ["/sys/class/hwmon/hwmon2/pwm1"]; | ||
}; | ||
|
||
services.hddfancontrol.smartctl = lib.mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = lib.mdDoc '' | ||
Probe temperature using smartctl instead of hddtemp or hdparm | ||
''; | ||
}; | ||
|
||
services.hddfancontrol.extraArgs = lib.mkOption { | ||
type = with types; listOf str; | ||
default = []; | ||
description = lib.mdDoc '' | ||
Extra commandline arguments for hddfancontrol | ||
''; | ||
example = ["--pwm-start-value=32" | ||
"--pwm-stop-value=0" | ||
"--spin-down-time=900"]; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable ( | ||
let args = lib.concatLists [ | ||
["-d"] cfg.disks | ||
["-p"] cfg.pwmPaths | ||
(lib.optional cfg.smartctl "--smartctl") | ||
cfg.extraArgs | ||
]; in { | ||
systemd.packages = [pkgs.hddfancontrol]; | ||
|
||
systemd.services.hddfancontrol = { | ||
enable = true; | ||
wantedBy = [ "multi-user.target" ]; | ||
environment.HDDFANCONTROL_ARGS = lib.escapeShellArgs args; | ||
}; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ./make-test-python.nix ({ pkgs, ... }: { | ||
name = "hddfancontrol"; | ||
meta = with pkgs.lib.maintainers; { | ||
maintainers = [ benley ]; | ||
}; | ||
|
||
nodes.machine = { ... }: { | ||
imports = [ ../modules/profiles/minimal.nix ]; | ||
|
||
services.hddfancontrol.enable = true; | ||
services.hddfancontrol.disks = ["/dev/vda"]; | ||
services.hddfancontrol.pwmPaths = ["/test/hwmon1/pwm1"]; | ||
services.hddfancontrol.extraArgs = ["--pwm-start-value=32" | ||
"--pwm-stop-value=0"]; | ||
|
||
systemd.services.hddfancontrol_fixtures = { | ||
description = "Install test fixtures for hddfancontrol"; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
}; | ||
script = '' | ||
mkdir -p /test/hwmon1 | ||
echo 255 > /test/hwmon1/pwm1 | ||
echo 2 > /test/hwmon1/pwm1_enable | ||
''; | ||
wantedBy = ["hddfancontrol.service"]; | ||
before = ["hddfancontrol.service"]; | ||
}; | ||
|
||
systemd.services.hddfancontrol.serviceConfig.ReadWritePaths = "/test"; | ||
}; | ||
|
||
# hddfancontrol.service will fail to start because qemu /dev/vda doesn't have | ||
# any thermal interfaces, but it should ensure that fans appear to be running | ||
# before it aborts. | ||
testScript = '' | ||
start_all() | ||
machine.wait_for_unit("multi-user.target") | ||
machine.succeed("journalctl -eu hddfancontrol.service|grep 'Setting fan speed'") | ||
machine.shutdown() | ||
''; | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ lib, python3Packages, fetchFromGitHub, hddtemp, hdparm, smartmontools }: | ||
|
||
python3Packages.buildPythonPackage rec { | ||
pname = "hddfancontrol"; | ||
version = "1.5.1"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "desbma"; | ||
repo = pname; | ||
rev = version; | ||
sha256 = "0b2grf98qnikayn18xll01dkm5pjpcjxdffgx1nyw9s0gqig8dg0"; | ||
}; | ||
|
||
propagatedBuildInputs = [ | ||
python3Packages.python-daemon | ||
hddtemp | ||
hdparm | ||
smartmontools | ||
]; | ||
|
||
postInstall = '' | ||
mkdir -p $out/etc/systemd/system | ||
substitute systemd/hddfancontrol.service $out/etc/systemd/system/hddfancontrol.service \ | ||
--replace /usr/bin/hddfancontrol $out/bin/hddfancontrol | ||
sed -i -e '/EnvironmentFile=.*/d' $out/etc/systemd/system/hddfancontrol.service | ||
''; | ||
|
||
meta = with lib; { | ||
description = "Dynamically control fan speed according to hard drive temperature on Linux"; | ||
homepage = "https://github.com/desbma/hddfancontrol"; | ||
license = licenses.gpl3; | ||
maintainers = with maintainers; [ benley ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters