about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/hardware/hddfancontrol.nix
blob: 746154e7aa17e24b93efa2d890187129462f68d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ config, lib, pkgs, ... }:

let
  cfg = config.services.hddfancontrol;
  types = lib.types;
in

{
  options = {

    services.hddfancontrol.enable = lib.mkEnableOption (lib.mdDoc "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 = {
        wantedBy = [ "multi-user.target" ];
        environment.HDDFANCONTROL_ARGS = lib.escapeShellArgs args;
        serviceConfig = {
          # Hardening
          PrivateNetwork = true;
        };
      };
    }
  );
}