[Nix-dev] new service: fancontrol.nix

Ilya Cassina ilya.cassina at gmail.com
Mon Oct 4 11:27:17 CEST 2010


Hello,

I wrote a service for fancontrol.

It needs some manual tweaking to make it work
  1. find sensors modules using ${lm_sensors}/sbin/sensors-detect and add them 
to boot.kernelModules
  2. find pwm/fans/temp correlations using ${lm_sensors}/sbin/pwmconfig
  3. write relevant values in /etc/nixos/configuration.nix under 
services.fancontrol.config (see example)

Hope that this can be somewhat useful (for me it is!).

Any comment is appreciated!

imc
-------------- next part --------------
# fancontrol daemon.
{ config, pkgs, ... }:

with pkgs.lib;

let

  cfg = config.services.fancontrol;
  fcCfg = cfg.config;

  inherit (pkgs) lm_sensors;

  confFile = pkgs.writeText "fancontrol"
  ''
    INTERVAL=${toString fcCfg.interval}
    FCTEMPS=${ concatStringsSep " " (map (f: f.pwm + "=" + f.temp ) fcCfg.fans)}
    FCFANS=${  concatStringsSep " " (map (f: f.pwm + "=" + f.fan  ) fcCfg.fans)}
    MINTEMP=${ concatStringsSep " " (map (f: f.pwm + "=" + (toString f.min  ) ) fcCfg.fans)}
    MAXTEMP=${ concatStringsSep " " (map (f: f.pwm + "=" + (toString f.max  ) ) fcCfg.fans)}
    MINSTART=${concatStringsSep " " (map (f: f.pwm + "=" + (toString f.start) ) fcCfg.fans)}
    MINSTOP=${ concatStringsSep " " (map (f: f.pwm + "=" + (toString f.stop ) ) fcCfg.fans)}
  '';

in

{

  ###### interface
  
  options = {
  
    services.fancontrol = {
    
      enable = mkOption {
        default = false;
        description = ''
          Whether to start the fancontrol daemon.
        '';
      };

      config = mkOption {
        default = null;
        description = ''
          Fancontrol configuration (usually from \${lm_sensors}/sbin/pwmconfig).
          Warning: you should enable relevant kernel modules in boot.kernelModules
          (you can usually find them using ${lm_sensors}/sbin/sensors-detect)
        '';
        example =
        ''
            {
                interval = 10;
                fans = [
                    {
                        pwm   = "hwmon0/device/pwm1";
                        temp  = "hwmon0/device/temp1_input";
                        fan   = "hwmon0/device/fan1_input";
                        min   = 25;  max  = 65;
                        start = 150; stop = 0;
                    }
                    {
                        pwm   = "hwmon0/device/pwm2";
                        temp  = "hwmon0/device/temp2_input";
                        fan   = "hwmon0/device/fan2_input";
                        min   = 20;  max  = 55;
                        start = 150; stop = 0;
                    }
                ];
            };
        '';
      };

    };
    
  };


  ###### implementation
  
  config = mkIf (cfg.enable && cfg.config != null && cfg.config.fans != []) {

    environment.systemPackages = [ lm_sensors ];

    jobs.fancontrol =
      { description = "fancontrol daemon";
        exec = "${pkgs.lm_sensors}/sbin/fancontrol ${confFile}";
      };
  };
}


More information about the nix-dev mailing list