bumblebee service: make bbswitch optional

+47 -35
+47 -35
nixos/modules/hardware/video/bumblebee.nix
··· 22 22 { 23 23 24 24 options = { 25 - hardware.bumblebee.enable = mkOption { 26 - default = false; 27 - type = types.bool; 28 - description = '' 29 - Enable the bumblebee daemon to manage Optimus hybrid video cards. 30 - This should power off secondary GPU until its use is requested 31 - by running an application with optirun. 25 + hardware.bumblebee = { 32 26 33 - Only nvidia driver is supported so far. 34 - ''; 35 - }; 36 - hardware.bumblebee.group = mkOption { 37 - default = "wheel"; 38 - example = "video"; 39 - type = types.str; 40 - description = ''Group for bumblebee socket''; 41 - }; 27 + enable = mkOption { 28 + default = false; 29 + type = types.bool; 30 + description = '' 31 + Enable the bumblebee daemon to manage Optimus hybrid video cards. 32 + This should power off secondary GPU until its use is requested 33 + by running an application with optirun. 34 + ''; 35 + }; 42 36 43 - hardware.bumblebee.connectDisplay = mkOption { 44 - default = false; 45 - type = types.bool; 46 - description = '' 47 - Set to true if you intend to connect your discrete card to a 48 - monitor. This option will set up your Nvidia card for EDID 49 - discovery and to turn on the monitor signal. 37 + group = mkOption { 38 + default = "wheel"; 39 + example = "video"; 40 + type = types.str; 41 + description = ''Group for bumblebee socket''; 42 + }; 50 43 51 - Only nvidia driver is supported so far. 52 - ''; 53 - }; 44 + connectDisplay = mkOption { 45 + default = false; 46 + type = types.bool; 47 + description = '' 48 + Set to true if you intend to connect your discrete card to a 49 + monitor. This option will set up your Nvidia card for EDID 50 + discovery and to turn on the monitor signal. 51 + 52 + Only nvidia driver is supported so far. 53 + ''; 54 + }; 55 + 56 + driver = mkOption { 57 + default = "nvidia"; 58 + type = types.enum [ "nvidia" "nouveau" ]; 59 + description = '' 60 + Set driver used by bumblebeed. Supported are nouveau and nvidia. 61 + ''; 62 + }; 63 + 64 + bbswitch = mkOption { 65 + default = true; 66 + type = types.bool; 67 + description = '' 68 + Set to true if you want to use bbswitch for power management of 69 + unused card. 70 + ''; 71 + }; 54 72 55 - hardware.bumblebee.driver = mkOption { 56 - default = "nvidia"; 57 - type = types.enum [ "nvidia" "nouveau" ]; 58 - description = '' 59 - Set driver used by bumblebeed. Supported are nouveau and nvidia. 60 - ''; 61 73 }; 62 74 }; 63 75 64 - config = mkIf config.hardware.bumblebee.enable { 76 + config = mkIf cfg.enable { 65 77 boot.blacklistedKernelModules = [ "nvidia-drm" "nvidia" "nouveau" ]; 66 - boot.kernelModules = [ "bbswitch" ]; 67 - boot.extraModulePackages = [ kernel.bbswitch ] ++ optional useNvidia kernel.nvidia_x11; 78 + boot.kernelModules = optional cfg.bbswitch [ "bbswitch" ]; 79 + boot.extraModulePackages = optional cfg.bbswitch kernel.bbswitch ++ optional useNvidia kernel.nvidia_x11; 68 80 69 81 environment.systemPackages = [ bumblebee primus ]; 70 82