at 25.11-pre 2.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.hardware.bumblebee; 9 10 kernel = config.boot.kernelPackages; 11 12 useNvidia = cfg.driver == "nvidia"; 13 14 bumblebee = pkgs.bumblebee.override { 15 inherit useNvidia; 16 useDisplayDevice = cfg.connectDisplay; 17 }; 18 19 useBbswitch = cfg.pmMethod == "bbswitch" || cfg.pmMethod == "auto" && useNvidia; 20 21 primus = pkgs.primus.override { 22 inherit useNvidia; 23 }; 24 25in 26 27{ 28 29 options = { 30 hardware.bumblebee = { 31 32 enable = lib.mkOption { 33 default = false; 34 type = lib.types.bool; 35 description = '' 36 Enable the bumblebee daemon to manage Optimus hybrid video cards. 37 This should power off secondary GPU until its use is requested 38 by running an application with optirun. 39 ''; 40 }; 41 42 group = lib.mkOption { 43 default = "wheel"; 44 example = "video"; 45 type = lib.types.str; 46 description = "Group for bumblebee socket"; 47 }; 48 49 connectDisplay = lib.mkOption { 50 default = false; 51 type = lib.types.bool; 52 description = '' 53 Set to true if you intend to connect your discrete card to a 54 monitor. This option will set up your Nvidia card for EDID 55 discovery and to turn on the monitor signal. 56 57 Only nvidia driver is supported so far. 58 ''; 59 }; 60 61 driver = lib.mkOption { 62 default = "nvidia"; 63 type = lib.types.enum [ 64 "nvidia" 65 "nouveau" 66 ]; 67 description = '' 68 Set driver used by bumblebeed. Supported are nouveau and nvidia. 69 ''; 70 }; 71 72 pmMethod = lib.mkOption { 73 default = "auto"; 74 type = lib.types.enum [ 75 "auto" 76 "bbswitch" 77 "switcheroo" 78 "none" 79 ]; 80 description = '' 81 Set preferred power management method for unused card. 82 ''; 83 }; 84 85 }; 86 }; 87 88 config = lib.mkIf cfg.enable { 89 boot.blacklistedKernelModules = [ 90 "nvidia-drm" 91 "nvidia" 92 "nouveau" 93 ]; 94 boot.kernelModules = lib.optional useBbswitch "bbswitch"; 95 boot.extraModulePackages = 96 lib.optional useBbswitch kernel.bbswitch 97 ++ lib.optional useNvidia kernel.nvidia_x11.bin; 98 99 environment.systemPackages = [ 100 bumblebee 101 primus 102 ]; 103 104 systemd.services.bumblebeed = { 105 description = "Bumblebee Hybrid Graphics Switcher"; 106 wantedBy = [ "multi-user.target" ]; 107 before = [ "display-manager.service" ]; 108 serviceConfig = { 109 ExecStart = "${bumblebee}/bin/bumblebeed --use-syslog -g ${cfg.group} --driver ${cfg.driver} --pm-method ${cfg.pmMethod}"; 110 }; 111 }; 112 }; 113}