summaryrefslogtreecommitdiff
path: root/modules/thinkpad.nix
blob: 9cbcd79932b10b15fa16f906968a585dab4f86f9 (plain)
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
{ lib, config, pkgs, ... }:

let cfg = config.this.laptop.thinkpad;
    mkZcfanConf = c: lib.generators.toKeyValue {
      mkKeyValue = lib.generators.mkKeyValueDefault {} " ";
    } c;
    zcfanConf = mkZcfanConf cfg.zcfan.settings;
    inherit (builtins) toString;
in
{
  options = {
    this.laptop.thinkpad = {
      enable = lib.mkEnableOption "thinkpad settings";
      trackpoint = {
        sensitivity = lib.mkOption {
          type = lib.types.int;
          default = 255;
        };
        speed = lib.mkOption {
          type = lib.types.int;
          default = 127;
        };
      };
      zcfan = {
        settings = lib.mkOption {
          type = with lib.types;
            attrsOf (oneOf [int str]);
          default = { };
          description = "Settings for zcfan.";
        };
      };
    };
  };

  config = lib.mkIf cfg.enable {
    boot.extraModprobeConfig = "options thinkpad_acpi fan_control=1";

    services.udev.extraRules = ''
      ACTION=="add", SUBSYSTEM=="input", ATTR{name}=="TPPS/2 IBM TrackPoint", ATTR{device/sensitivity}="${toString cfg.trackpoint.sensitivity}", ATTR{device/speed}="${toString cfg.trackpoint.speed}"
    '';

    environment.etc."zcfan.conf" = lib.mkIf (zcfanConf != "") { text = zcfanConf; };
    environment.systemPackages = [ pkgs.zcfan ];
    systemd.packages = [ pkgs.zcfan ];
    systemd.services.zcfan.wantedBy = [ "multi-user.target" ];
  };
}