1 # The bumblebee package allows a program to be rendered on an
2 # dedicated video card by spawning an additional X11 server and
3 # streaming the results via VirtualGL or primus to the primary server.
5 # The package is rather chaotic; it's also quite recent.
6 # As it may change a lot, some of the hacks in this nix expression
7 # will hopefully not be needed in the future anymore.
10 # 1. make sure that the 'bbswitch' kernel module is installed,
11 # 2. then run 'bumblebeed' as root
12 # 3. Then either 'optirun glxinfo' or 'primusrun glxinfo' as user.
14 # The glxinfo output should indicate the Nvidia driver is being used
15 # and all expected extensions are supported.
17 # To use at startup, see hardware.bumblebee options.
19 { stdenv, lib, fetchurl, fetchpatch, pkg-config, help2man, makeWrapper
21 , libX11, xorgserver, kmod, xf86videonouveau
22 , nvidia_x11, virtualgl, libglvnd
23 , automake111x, autoconf
24 # The below should only be non-null in a x86_64 system. On a i686
25 # system the above nvidia_x11 and virtualgl will be the i686 packages.
26 # TODO: Confusing. Perhaps use "SubArch" instead of i686?
27 , nvidia_x11_i686 ? null
28 , libglvnd_i686 ? null
29 , useDisplayDevice ? false
30 , extraNvidiaDeviceOptions ? ""
31 , extraNouveauDeviceOptions ? ""
36 nvidia_x11s = [ nvidia_x11 ]
37 ++ lib.optional nvidia_x11.useGLVND libglvnd
38 ++ lib.optionals (nvidia_x11_i686 != null)
39 ([ nvidia_x11_i686 ] ++ lib.optional nvidia_x11_i686.useGLVND libglvnd_i686);
41 nvidiaLibs = lib.makeLibraryPath nvidia_x11s;
43 bbdPath = lib.makeBinPath [ kmod xorgserver ];
45 xmodules = lib.concatStringsSep "," (map (x: "${x.out or x}/lib/xorg/modules") ([ xorgserver ] ++ lib.optional (!useNvidia) xf86videonouveau));
47 modprobePatch = fetchpatch {
48 url = "https://github.com/Bumblebee-Project/Bumblebee/commit/1ada79fe5916961fc4e4917f8c63bb184908d986.patch";
49 sha256 = "02vq3vba6nx7gglpjdfchws9vjhs1x02a543yvqrxqpvvdfim2x2";
51 libkmodPatch = fetchpatch {
52 url = "https://github.com/Bumblebee-Project/Bumblebee/commit/deceb14cdf2c90ff64ebd1010a674305464587da.patch";
53 sha256 = "00c05i5lxz7vdbv445ncxac490vbl5g9w3vy3gd71qw1f0si8vwh";
55 gcc10Patch = fetchpatch {
56 url = "https://github.com/Bumblebee-Project/Bumblebee/commit/f94a118a88cd76e2dbea33d735bd53cf54b486a1.patch";
57 hash = "sha256-3b5tLoMrGYSdg9Hz5bh0c44VIrbSZrY56JpWEyU/Pik=";
60 in stdenv.mkDerivation rec {
65 url = "https://www.bumblebee-project.org/${pname}-${version}.tar.gz";
66 sha256 = "03p3gvx99lwlavznrpg9l7jnl1yfg2adcj8jcjj0gxp20wxp060h";
77 # By default we don't want to use a display device
78 nvidiaDeviceOptions = lib.optionalString (!useDisplayDevice) ''
79 # Disable display device
80 Option "UseEDID" "false"
81 Option "UseDisplayDevice" "none"
82 '' + extraNvidiaDeviceOptions;
84 nouveauDeviceOptions = extraNouveauDeviceOptions;
86 # the have() function is deprecated and not available to bash completions the
87 # way they are currently loaded in NixOS, so use _have. See #10936
89 substituteInPlace scripts/bash_completion/bumblebee \
90 --replace "have optirun" "_have optirun"
94 # Don't use a special group, just reuse wheel.
95 substituteInPlace configure \
96 --replace 'CONF_GID="bumblebee"' 'CONF_GID="wheel"'
98 # Apply configuration options
99 substituteInPlace conf/xorg.conf.nvidia \
100 --subst-var nvidiaDeviceOptions
102 substituteInPlace conf/xorg.conf.nouveau \
103 --subst-var nouveauDeviceOptions
106 # Build-time dependencies of bumblebeed and optirun.
107 # Note that it has several runtime dependencies.
108 buildInputs = [ libX11 glib libbsd kmod ];
109 nativeBuildInputs = [ makeWrapper pkg-config help2man automake111x autoconf ];
111 # The order of LDPATH is very specific: First X11 then the host
112 # environment then the optional sub architecture paths.
114 # The order for MODPATH is the opposite: First the environment that
115 # includes the acceleration driver. As this is used for the X11
116 # server, which runs under the host architecture, this does not
117 # include the sub architecture components.
119 "--with-udev-rules=$out/lib/udev/rules.d"
121 #"CONF_PRIMUS_LD_PATH=${primusLibs}"
122 ] ++ lib.optionals useNvidia [
123 "CONF_LDPATH_NVIDIA=${nvidiaLibs}"
124 "CONF_MODPATH_NVIDIA=${nvidia_x11.bin}/lib/xorg/modules"
128 "-DX_MODULE_APPENDS=\\\"${xmodules}\\\""
132 wrapProgram "$out/sbin/bumblebeed" \
133 --prefix PATH : "${bbdPath}"
135 wrapProgram "$out/bin/optirun" \
136 --prefix PATH : "${virtualgl}/bin"
140 description = "Daemon for managing Optimus videocards (power-on/off, spawns xservers)";
141 homepage = "https://github.com/Bumblebee-Project/Bumblebee";
142 license = licenses.gpl3;
143 maintainers = with maintainers; [ abbradar ];
144 platforms = platforms.linux;