@@ -16,89 +16,56 @@
1616#
1717# To use at startup, see hardware.bumblebee options.
1818
19−# This nix expression supports for now only the native nvidia driver.
20−# It should not be hard to generalize this approach to support the
21−# nouveau driver as well (parameterize hostEnv, i686Env over the
22−# module package, and parameterize the two wrappers as well)
23−
24−{ stdenv, fetchurl, pkgconfig, help2man
25−, libX11, glibc, glib, libbsd
26−, makeWrapper, buildEnv, module_init_tools
27−, xorg, xkeyboard_config
28−, nvidia_x11, virtualgl
19+{ stdenv, lib, fetchurl, pkgconfig, help2man, makeWrapper
20+, glib, libbsd
21+, libX11, libXext, xorgserver, xkbcomp, module_init_tools, xkeyboard_config, xf86videonouveau
22+, nvidia_x11, virtualgl, primusLib
2923# The below should only be non-null in a x86_64 system. On a i686
3024# system the above nvidia_x11 and virtualgl will be the i686 packages.
3125# TODO: Confusing. Perhaps use "SubArch" instead of i686?
3226, nvidia_x11_i686 ? null
33−, virtualgl_i686 ? null
27+, primusLib_i686 ? null
3428, useDisplayDevice ? false
35−, extraDeviceOptions ? ""
29+, extraNvidiaDeviceOptions ? ""
30+, extraNouveauDeviceOptions ? ""
31+, useNvidia ? true
3632}:
37−with stdenv.lib;
33+
3834let
3935 version = "3.2.1";
40− name = "bumblebee-${version}";
4136
42− # Isolated X11 environment without the acceleration driver module.
43− # Includes the rest of the components needed for bumblebeed and
44− # optirun to spawn the second X server and to connect to it.
45− x11Env = buildEnv {
46− name = "bumblebee-env";
47− paths = [
48− module_init_tools
49− xorg.xorgserver
50− xorg.xrandr
51− xorg.xrdb
52− xorg.setxkbmap
53− xorg.libX11
54− xorg.libXext
55− xorg.xf86inputevdev
56− ];
57− };
37+ primus = if useNvidia then primusLib else primusLib.override { nvidia_x11 = null; };
38+ primus_i686 = if useNvidia then primusLib_i686 else primusLib_i686.override { nvidia_x11 = null; };
5839
59− # The environment for the host architecture.
60− hostEnv = buildEnv {
61− name = "bumblebee-x64-env";
62− paths = [
63− nvidia_x11
64− virtualgl
65− ];
66− };
40+ primusLibs = lib.makeLibraryPath ([primus] ++ lib.optional (primusLib_i686 != null) primus_i686);
6741
68− # The environment for the sub architecture, i686, if there is one
69− i686Env = if virtualgl_i686 != null
70− then buildEnv {
71− name = "bumblebee-i686-env";
72− paths = [
73− nvidia_x11_i686
74− virtualgl_i686
75− ];
76− }
77− else null;
42+ nvidia_x11s = [nvidia_x11] ++ lib.optional (nvidia_x11_i686 != null) nvidia_x11_i686;
7843
79− allEnvs = [hostEnv] ++ optional (i686Env != null) i686Env;
80− ldPathString = makeLibraryPath allEnvs;
44+ nvidiaLibs = lib.makeLibraryPath nvidia_x11s;
8145
82− # By default we don't want to use a display device
83− deviceOptions = if useDisplayDevice
84− then ""
85− else ''
46+ bbdPath = lib.makeSearchPath "bin" [ module_init_tools xorgserver ];
47+ bbdLibs = lib.makeLibraryPath [ libX11 libXext ];
8648
87− # Disable display device
88− Option "UseEDID" "false"
89− Option "UseDisplayDevice" "none"
90− ''
91− + extraDeviceOptions;
49+ xmodules = lib.concatStringsSep "," (map (x: "${x}/lib/xorg/modules") ([ xorgserver ] ++ lib.optional (!useNvidia) xf86videonouveau));
9250
93−in stdenv.mkDerivation {
94− inherit name deviceOptions;
51+in stdenv.mkDerivation rec {
52+ name = "bumblebee-${version}";
9553
9654 src = fetchurl {
9755 url = "http://bumblebee-project.org/${name}.tar.gz";
9856 sha256 = "03p3gvx99lwlavznrpg9l7jnl1yfg2adcj8jcjj0gxp20wxp060h";
9957 };
10058
101− patches = [ ./xopts.patch ./nvidia-conf.patch];
59+ patches = [ ./nixos.patch ];
60+
61+ # By default we don't want to use a display device
62+ nvidiaDeviceOptions = lib.optionalString (!useDisplayDevice) ''
63+ # Disable display device
64+ Option "UseEDID" "false"
65+ Option "UseDisplayDevice" "none"
66+ '' + extraNvidiaDeviceOptions;
67+
68+ nouveauDeviceOptions = extraNouveauDeviceOptions;
10269
10370 preConfigure = ''
10471 # Substitute the path to the actual modinfo program in module.c.
@@ -114,12 +81,16 @@ in stdenv.mkDerivation {
11481
11582 # Apply configuration options
11683 substituteInPlace conf/xorg.conf.nvidia \
117− --subst-var deviceOptions
84+ --subst-var nvidiaDeviceOptions
85+
86+ substituteInPlace conf/xorg.conf.nouveau \
87+ --subst-var nouveauDeviceOptions
11888 '';
11989
12090 # Build-time dependencies of bumblebeed and optirun.
12191 # Note that it has several runtime dependencies.
122− buildInputs = [ stdenv makeWrapper pkgconfig help2man libX11 glib libbsd ];
92+ buildInputs = [ libX11 glib libbsd ];
93+ nativeBuildInputs = [ makeWrapper pkgconfig help2man ];
12394
12495 # The order of LDPATH is very specific: First X11 then the host
12596 # environment then the optional sub architecture paths.
@@ -130,33 +101,33 @@ in stdenv.mkDerivation {
130101 # include the sub architecture components.
131102 configureFlags = [
132103 "--with-udev-rules=$out/lib/udev/rules.d"
133− "CONF_DRIVER=nvidia"
134− "CONF_DRIVER_MODULE_NVIDIA=nvidia"
135− "CONF_LDPATH_NVIDIA=${x11Env}/lib:${ldPathString}"
136− "CONF_MODPATH_NVIDIA=${hostEnv}/lib/xorg/modules,${x11Env}/lib/xorg/modules"
104+ # see #10282
105+ #"CONF_PRIMUS_LD_PATH=${primusLibs}"
106+ ] ++ lib.optionals useNvidia [
107+ "CONF_LDPATH_NVIDIA=${nvidiaLibs}"
108+ "CONF_MODPATH_NVIDIA=${nvidia_x11}/lib/xorg/modules"
109+ ];
110+
111+ CFLAGS = [
112+ "-DX_MODULE_APPENDS=\\\"${xmodules}\\\""
113+ "-DX_XKB_DIR=\\\"${xkeyboard_config}/etc/X11/xkb\\\""
137114 ];
138115
139− # create a wrapper environment for bumblebeed and optirun
140116 postInstall = ''
141117 wrapProgram "$out/sbin/bumblebeed" \
142− --prefix PATH : "${x11Env}/sbin:${x11Env}/bin:${hostEnv}/bin:\$PATH" \
143− --prefix LD_LIBRARY_PATH : "${x11Env}/lib:${hostEnv}/lib:\$LD_LIBRARY_PATH" \
144− --set FONTCONFIG_FILE "/etc/fonts/fonts.conf" \
145− --set XKB_BINDIR "${xorg.xkbcomp}/bin" \
146− --set XKB_DIR "${xkeyboard_config}/etc/X11/xkb"
118+ --set XKB_BINDIR "${xkbcomp}/bin" \
119+ --prefix PATH : "${bbdPath}" \
120+ --prefix LD_LIBRARY_PATH : "${bbdLibs}"
147121
148122 wrapProgram "$out/bin/optirun" \
149− --prefix PATH : "${hostEnv}/bin"
150− '' + (if i686Env == null
151− then ""
152− else ''
153− makeWrapper "$out/bin/.optirun-wrapped" "$out/bin/optirun32" \
154− --prefix PATH : "${i686Env}/bin"
155− '');
156−
157− meta = {
123+ --prefix PATH : "${virtualgl}/bin"
124+ '';
125+
126+ meta = with stdenv.lib; {
158127 homepage = http://github.com/Bumblebee-Project/Bumblebee;
159128 description = "Daemon for managing Optimus videocards (power-on/off, spawns xservers)";
160− license = stdenv.lib.licenses.gpl3;
129+ platforms = platforms.linux;
130+ license = licenses.gpl3;
131+ maintainers = with maintainers; [ abbradar ];
161132 };
162133}