2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-02-08 18:47:51 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-12-20 10:51:24 +00:00
|
|
|
let
|
2015-12-04 21:36:01 +00:00
|
|
|
cfg = config.hardware.bumblebee;
|
|
|
|
|
2014-12-20 10:51:24 +00:00
|
|
|
kernel = config.boot.kernelPackages;
|
2015-12-04 21:36:01 +00:00
|
|
|
|
|
|
|
useNvidia = cfg.driver == "nvidia";
|
|
|
|
|
|
|
|
bumblebee = pkgs.bumblebee.override {
|
|
|
|
inherit useNvidia;
|
|
|
|
useDisplayDevice = cfg.connectDisplay;
|
|
|
|
};
|
|
|
|
|
|
|
|
primus = pkgs.primus.override {
|
|
|
|
inherit useNvidia;
|
|
|
|
};
|
2014-12-20 10:51:24 +00:00
|
|
|
|
|
|
|
in
|
2014-02-08 18:47:51 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
2016-11-21 14:16:35 +00:00
|
|
|
hardware.bumblebee = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enable the bumblebee daemon to manage Optimus hybrid video cards.
|
|
|
|
This should power off secondary GPU until its use is requested
|
|
|
|
by running an application with optirun.
|
|
|
|
'';
|
|
|
|
};
|
2015-12-04 21:36:01 +00:00
|
|
|
|
2016-11-21 14:16:35 +00:00
|
|
|
group = mkOption {
|
|
|
|
default = "wheel";
|
|
|
|
example = "video";
|
|
|
|
type = types.str;
|
|
|
|
description = ''Group for bumblebee socket'';
|
|
|
|
};
|
2014-12-20 10:51:24 +00:00
|
|
|
|
2016-11-21 14:16:35 +00:00
|
|
|
connectDisplay = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Set to true if you intend to connect your discrete card to a
|
|
|
|
monitor. This option will set up your Nvidia card for EDID
|
|
|
|
discovery and to turn on the monitor signal.
|
|
|
|
|
|
|
|
Only nvidia driver is supported so far.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
driver = mkOption {
|
|
|
|
default = "nvidia";
|
|
|
|
type = types.enum [ "nvidia" "nouveau" ];
|
|
|
|
description = ''
|
|
|
|
Set driver used by bumblebeed. Supported are nouveau and nvidia.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bbswitch = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Set to true if you want to use bbswitch for power management of
|
|
|
|
unused card.
|
|
|
|
'';
|
|
|
|
};
|
2015-12-04 21:36:01 +00:00
|
|
|
|
|
|
|
};
|
2014-02-08 18:47:51 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 14:16:35 +00:00
|
|
|
config = mkIf cfg.enable {
|
2016-11-08 15:18:42 +00:00
|
|
|
boot.blacklistedKernelModules = [ "nvidia-drm" "nvidia" "nouveau" ];
|
2016-11-21 14:16:35 +00:00
|
|
|
boot.kernelModules = optional cfg.bbswitch [ "bbswitch" ];
|
|
|
|
boot.extraModulePackages = optional cfg.bbswitch kernel.bbswitch ++ optional useNvidia kernel.nvidia_x11;
|
2014-02-08 18:47:51 +00:00
|
|
|
|
2015-12-04 21:36:01 +00:00
|
|
|
environment.systemPackages = [ bumblebee primus ];
|
2014-02-08 18:47:51 +00:00
|
|
|
|
|
|
|
systemd.services.bumblebeed = {
|
|
|
|
description = "Bumblebee Hybrid Graphics Switcher";
|
2016-11-21 14:16:22 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
before = [ "display-manager.service" ];
|
2014-02-08 18:47:51 +00:00
|
|
|
serviceConfig = {
|
2015-12-04 21:36:01 +00:00
|
|
|
ExecStart = "${bumblebee}/bin/bumblebeed --use-syslog -g ${cfg.group} --driver ${cfg.driver}";
|
2014-02-08 18:47:51 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|