2014-04-14 16:26:48 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2014-12-20 02:51:24 -08:00
|
|
|
let
|
2015-12-05 00:36:01 +03:00
|
|
|
cfg = config.hardware.bumblebee;
|
|
|
|
|
2014-12-20 02:51:24 -08:00
|
|
|
kernel = config.boot.kernelPackages;
|
2015-12-05 00:36:01 +03:00
|
|
|
|
|
|
|
useNvidia = cfg.driver == "nvidia";
|
|
|
|
|
|
|
|
bumblebee = pkgs.bumblebee.override {
|
|
|
|
inherit useNvidia;
|
|
|
|
useDisplayDevice = cfg.connectDisplay;
|
|
|
|
};
|
|
|
|
|
2017-02-19 22:46:47 -09:00
|
|
|
useBbswitch = cfg.pmMethod == "bbswitch" || cfg.pmMethod == "auto" && useNvidia;
|
2016-11-22 02:33:39 +03:00
|
|
|
|
2015-12-05 00:36:01 +03:00
|
|
|
primus = pkgs.primus.override {
|
|
|
|
inherit useNvidia;
|
|
|
|
};
|
2014-12-20 02:51:24 -08:00
|
|
|
|
|
|
|
in
|
2014-02-08 19:47:51 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
2016-11-21 17:16:35 +03:00
|
|
|
hardware.bumblebee = {
|
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
enable = lib.mkOption {
|
2016-11-21 17:16:35 +03:00
|
|
|
default = false;
|
2024-08-24 22:05:31 +02:00
|
|
|
type = lib.types.bool;
|
2016-11-21 17:16:35 +03:00
|
|
|
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-05 00:36:01 +03:00
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
group = lib.mkOption {
|
2016-11-21 17:16:35 +03:00
|
|
|
default = "wheel";
|
|
|
|
example = "video";
|
2024-08-24 22:05:31 +02:00
|
|
|
type = lib.types.str;
|
2021-01-24 09:19:10 +00:00
|
|
|
description = "Group for bumblebee socket";
|
2016-11-21 17:16:35 +03:00
|
|
|
};
|
2014-12-20 02:51:24 -08:00
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
connectDisplay = lib.mkOption {
|
2016-11-21 17:16:35 +03:00
|
|
|
default = false;
|
2024-08-24 22:05:31 +02:00
|
|
|
type = lib.types.bool;
|
2016-11-21 17:16:35 +03:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
driver = lib.mkOption {
|
2016-11-21 17:16:35 +03:00
|
|
|
default = "nvidia";
|
2024-08-24 22:05:31 +02:00
|
|
|
type = lib.types.enum [
|
|
|
|
"nvidia"
|
|
|
|
"nouveau"
|
|
|
|
];
|
2016-11-21 17:16:35 +03:00
|
|
|
description = ''
|
|
|
|
Set driver used by bumblebeed. Supported are nouveau and nvidia.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
pmMethod = lib.mkOption {
|
2016-11-22 02:33:39 +03:00
|
|
|
default = "auto";
|
2024-08-24 22:05:31 +02:00
|
|
|
type = lib.types.enum [
|
|
|
|
"auto"
|
|
|
|
"bbswitch"
|
|
|
|
"switcheroo"
|
|
|
|
"none"
|
|
|
|
];
|
2016-11-21 17:16:35 +03:00
|
|
|
description = ''
|
2016-11-22 02:33:39 +03:00
|
|
|
Set preferred power management method for unused card.
|
2016-11-21 17:16:35 +03:00
|
|
|
'';
|
|
|
|
};
|
2015-12-05 00:36:01 +03:00
|
|
|
|
|
|
|
};
|
2014-02-08 19:47:51 +01:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:31 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2016-11-08 18:18:42 +03:00
|
|
|
boot.blacklistedKernelModules = [
|
|
|
|
"nvidia-drm"
|
|
|
|
"nvidia"
|
|
|
|
"nouveau"
|
|
|
|
];
|
2024-08-24 22:05:31 +02:00
|
|
|
boot.kernelModules = lib.optional useBbswitch "bbswitch";
|
|
|
|
boot.extraModulePackages =
|
|
|
|
lib.optional useBbswitch kernel.bbswitch
|
|
|
|
++ lib.optional useNvidia kernel.nvidia_x11.bin;
|
2024-12-10 20:29:24 +01:00
|
|
|
|
2015-12-05 00:36:01 +03:00
|
|
|
environment.systemPackages = [
|
|
|
|
bumblebee
|
|
|
|
primus
|
|
|
|
];
|
2014-02-08 19:47:51 +01:00
|
|
|
|
|
|
|
systemd.services.bumblebeed = {
|
|
|
|
description = "Bumblebee Hybrid Graphics Switcher";
|
2016-11-21 17:16:22 +03:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
before = [ "display-manager.service" ];
|
2014-02-08 19:47:51 +01:00
|
|
|
serviceConfig = {
|
2016-11-22 02:33:39 +03:00
|
|
|
ExecStart = "${bumblebee}/bin/bumblebeed --use-syslog -g ${cfg.group} --driver ${cfg.driver} --pm-method ${cfg.pmMethod}";
|
2014-02-08 19:47:51 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|