nixos/preload: init
[NixPkgs.git] / nixos / modules / hardware / video / webcam / facetimehd.nix
bloba0ec9c98a54c918b59b9e5b06ca9ac60abbaed31
1 { config, lib, pkgs, ... }:
3 with lib;
5 let
7   cfg = config.hardware.facetimehd;
9   kernelPackages = config.boot.kernelPackages;
15   options.hardware.facetimehd.enable = mkEnableOption (lib.mdDoc "the facetimehd kernel module");
17   options.hardware.facetimehd.withCalibration = mkOption {
18     default = false;
19     example = true;
20     type = types.bool;
21     description = lib.mdDoc ''
22       Whether to include sensor calibration files for facetimehd.
23       This makes colors look much better but is experimental, see
24       <https://github.com/patjak/facetimehd/wiki/Extracting-the-sensor-calibration-files>
25       for details.
26     '';
27   };
29   config = mkIf cfg.enable {
31     boot.kernelModules = [ "facetimehd" ];
33     boot.blacklistedKernelModules = [ "bdc_pci" ];
35     boot.extraModulePackages = [ kernelPackages.facetimehd ];
37     hardware.firmware = [ pkgs.facetimehd-firmware ]
38       ++ optional cfg.withCalibration pkgs.facetimehd-calibration;
40     # unload module during suspend/hibernate as it crashes the whole system
41     powerManagement.powerDownCommands = ''
42       ${pkgs.kmod}/bin/lsmod | ${pkgs.gnugrep}/bin/grep -q "^facetimehd" && ${pkgs.kmod}/bin/rmmod -f -v facetimehd
43     '';
45     # and load it back on resume
46     powerManagement.resumeCommands = ''
47       ${pkgs.kmod}/bin/modprobe -v facetimehd
48     '';
50   };