git.iko.soy/typeable/nixpkgs
on master help sign in
bumblebee: cleanup, fix virtualgl, add useNvidia flag
commit95629cf6f83cee1b8200f6fd408a206ea4e858b1 authorNikolay Amiantov <ab@fmap.me> dateSat 5 Dec 2015, 00:35 (11 years ago) parent3b1ab88
5 files changed+138−114
pkgs/tools/X11/bumblebee/default.nix+55−84 pkgs/tools/X11/bumblebee/nixos.patch+81 pkgs/tools/X11/bumblebee/nvidia-conf.patch−11 pkgs/tools/X11/bumblebee/xopts.patch−11 pkgs/top-level/all-packages.nix+2−8
pkgs/tools/X11/bumblebee/default.nix+55−84
@@ -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}
pkgs/tools/X11/bumblebee/nixos.patchnew file+81
@@ -0,0 +1,81 @@
1+diff --git a/conf/xorg.conf.nouveau b/conf/xorg.conf.nouveau
2+index 87e48cb..60d6eaf 100644
3+--- a/conf/xorg.conf.nouveau
4++++ b/conf/xorg.conf.nouveau
5+@@ -15,4 +15,5 @@ Section "Device"
6+ # This Setting is needed on Ubuntu 13.04.
7+ # BusID "PCI:01:00:0"
8+
9++@nouveauDeviceOptions@
10+ EndSection
11+diff --git a/conf/xorg.conf.nvidia b/conf/xorg.conf.nvidia
12+index c3107f9..17072f4 100644
13+--- a/conf/xorg.conf.nvidia
14++++ b/conf/xorg.conf.nvidia
15+@@ -29,6 +29,6 @@ Section "Device"
16+ Option "ProbeAllGpus" "false"
17+
18+ Option "NoLogo" "true"
19+- Option "UseEDID" "false"
20+- Option "UseDisplayDevice" "none"
21++
22++@nvidiaDeviceOptions@
23+ EndSection
24+diff --git a/src/bbsecondary.c b/src/bbsecondary.c
25+index 71a6b73..a682d8a 100644
26+--- a/src/bbsecondary.c
27++++ b/src/bbsecondary.c
28+@@ -145,6 +145,23 @@ bool start_secondary(bool need_secondary) {
29+ }
30+
31+ bb_log(LOG_INFO, "Starting X server on display %s.\n", bb_config.x_display);
32++ const char mod_appends[] = X_MODULE_APPENDS;
33++
34++ char *mod_path;
35++ int pathlen = strlen(bb_config.mod_path);
36++ if (pathlen == 0) {
37++ mod_path = mod_appends;
38++ } else {
39++ mod_path = malloc(pathlen + 1 + sizeof(mod_appends));
40++ if (!mod_path) {
41++ set_bb_error("Could not allocate memory for modules path\n");
42++ return false;
43++ }
44++ strcpy(mod_path, bb_config.mod_path);
45++ mod_path[pathlen] = ',';
46++ strcpy(mod_path + pathlen + 1, mod_appends);
47++ }
48++
49+ char *x_argv[] = {
50+ XORG_BINARY,
51+ bb_config.x_display,
52+@@ -153,24 +170,25 @@ bool start_secondary(bool need_secondary) {
53+ "-sharevts",
54+ "-nolisten", "tcp",
55+ "-noreset",
56++ "-logfile", "/var/log/X.bumblebee.log",
57++ "-xkbdir", X_XKB_DIR,
58+ "-verbose", "3",
59+ "-isolateDevice", pci_id,
60+- "-modulepath", bb_config.mod_path, // keep last
61++ "-modulepath", mod_path,
62+ NULL
63+ };
64+ enum {n_x_args = sizeof(x_argv) / sizeof(x_argv[0])};
65+- if (!*bb_config.mod_path) {
66+- x_argv[n_x_args - 3] = 0; //remove -modulepath if not set
67+- }
68+ //close any previous pipe, if it (still) exists
69+ if (bb_status.x_pipe[0] != -1){close(bb_status.x_pipe[0]); bb_status.x_pipe[0] = -1;}
70+ if (bb_status.x_pipe[1] != -1){close(bb_status.x_pipe[1]); bb_status.x_pipe[1] = -1;}
71+ //create a new pipe
72+ if (pipe2(bb_status.x_pipe, O_NONBLOCK | O_CLOEXEC)){
73+ set_bb_error("Could not create output pipe for X");
74++ if (pathlen > 0) free(mod_path);
75+ return false;
76+ }
77+ bb_status.x_pid = bb_run_fork_ld_redirect(x_argv, bb_config.ld_path, bb_status.x_pipe[1]);
78++ if (pathlen > 0) free(mod_path);
79+ //close the end of the pipe that is not ours
80+ if (bb_status.x_pipe[1] != -1){close(bb_status.x_pipe[1]); bb_status.x_pipe[1] = -1;}
81+ }
pkgs/tools/X11/bumblebee/nvidia-conf.patchdeleted−11
@@ -1,11 +0,0 @@
1−--- bumblebee-3.2.1/conf/xorg.conf.nvidia
2−+++ bumblebee-3.2.1/conf/xorg.conf.nvidia
3−@@ -29,6 +29,5 @@ Section "Device"
4− Option "ProbeAllGpus" "false"
5−
6− Option "NoLogo" "true"
7−- Option "UseEDID" "false"
8−- Option "UseDisplayDevice" "none"
9−+@deviceOptions@
10− EndSection
11−
pkgs/tools/X11/bumblebee/xopts.patchdeleted−11
@@ -1,11 +0,0 @@
1−--- bumblebee-3.2.1/src/bbsecondary.c 2012-02-05 00:03:06.003439638 +0100
2−+++ bumblebee-3.2.1/src/bbsecondary.c 2012-02-05 00:46:38.017382619 +0100
3−@@ -149,6 +149,8 @@
4− "-sharevts",
5− "-nolisten", "tcp",
6− "-noreset",
7−+ "-xkbdir", getenv("XKB_DIR"),
8−+ "-logfile", "/var/log/X.bumblebee.log",
9− "-verbose", "3",
10− "-isolateDevice", pci_id,
11− "-modulepath",
pkgs/top-level/all-packages.nix+2−8
@@ -13410,17 +13410,11 @@ let
1341013410 nvidia_x11_i686 = if system == "x86_64-linux"
1341113411 then pkgsi686Linux.linuxPackages.nvidia_x11.override { libsOnly = true; }
1341213412 else null;
13413− virtualgl = virtualgl;
13414− virtualgl_i686 = if system == "x86_64-linux"
13415− then pkgsi686Linux.virtualgl
13413+ primusLib_i686 = if system == "x86_64-linux"
13414+ then pkgsi686Linux.primusLib
1341613415 else null;
1341713416 };
1341813417
13419− # use if you intend to connect the nvidia card to a monitor
13420− bumblebee_display = bumblebee.override {
13421− useDisplayDevice = true;
13422− };
13423−
1342413418 vkeybd = callPackage ../applications/audio/vkeybd {};
1342513419
1342613420 vlc = callPackage ../applications/video/vlc {