lol

bumblebee: cleanup, fix virtualgl, add useNvidia flag

+137 -113
+54 -83
pkgs/tools/X11/bumblebee/default.nix
··· 16 16 # 17 17 # To use at startup, see hardware.bumblebee options. 18 18 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 29 23 # The below should only be non-null in a x86_64 system. On a i686 30 24 # system the above nvidia_x11 and virtualgl will be the i686 packages. 31 25 # TODO: Confusing. Perhaps use "SubArch" instead of i686? 32 26 , nvidia_x11_i686 ? null 33 - , virtualgl_i686 ? null 27 + , primusLib_i686 ? null 34 28 , useDisplayDevice ? false 35 - , extraDeviceOptions ? "" 29 + , extraNvidiaDeviceOptions ? "" 30 + , extraNouveauDeviceOptions ? "" 31 + , useNvidia ? true 36 32 }: 37 - with stdenv.lib; 33 + 38 34 let 39 35 version = "3.2.1"; 40 - name = "bumblebee-${version}"; 41 36 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; }; 58 39 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); 67 41 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; 78 43 79 - allEnvs = [hostEnv] ++ optional (i686Env != null) i686Env; 80 - ldPathString = makeLibraryPath allEnvs; 44 + nvidiaLibs = lib.makeLibraryPath nvidia_x11s; 81 45 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 ]; 86 48 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)); 92 50 93 - in stdenv.mkDerivation { 94 - inherit name deviceOptions; 51 + in stdenv.mkDerivation rec { 52 + name = "bumblebee-${version}"; 95 53 96 54 src = fetchurl { 97 55 url = "http://bumblebee-project.org/${name}.tar.gz"; 98 56 sha256 = "03p3gvx99lwlavznrpg9l7jnl1yfg2adcj8jcjj0gxp20wxp060h"; 99 57 }; 100 58 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; 102 69 103 70 preConfigure = '' 104 71 # Substitute the path to the actual modinfo program in module.c. ··· 114 81 115 82 # Apply configuration options 116 83 substituteInPlace conf/xorg.conf.nvidia \ 117 - --subst-var deviceOptions 84 + --subst-var nvidiaDeviceOptions 85 + 86 + substituteInPlace conf/xorg.conf.nouveau \ 87 + --subst-var nouveauDeviceOptions 118 88 ''; 119 89 120 90 # Build-time dependencies of bumblebeed and optirun. 121 91 # 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 ]; 123 94 124 95 # The order of LDPATH is very specific: First X11 then the host 125 96 # environment then the optional sub architecture paths. ··· 130 101 # include the sub architecture components. 131 102 configureFlags = [ 132 103 "--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" 137 109 ]; 138 110 139 - # create a wrapper environment for bumblebeed and optirun 111 + CFLAGS = [ 112 + "-DX_MODULE_APPENDS=\\\"${xmodules}\\\"" 113 + "-DX_XKB_DIR=\\\"${xkeyboard_config}/etc/X11/xkb\\\"" 114 + ]; 115 + 140 116 postInstall = '' 141 117 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}" 147 121 148 122 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 - ''); 123 + --prefix PATH : "${virtualgl}/bin" 124 + ''; 156 125 157 - meta = { 126 + meta = with stdenv.lib; { 158 127 homepage = http://github.com/Bumblebee-Project/Bumblebee; 159 128 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 ]; 161 132 }; 162 133 }
+81
pkgs/tools/X11/bumblebee/nixos.patch
··· 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 + }
-11
pkgs/tools/X11/bumblebee/nvidia-conf.patch
··· 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 -
-11
pkgs/tools/X11/bumblebee/xopts.patch
··· 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",
+2 -8
pkgs/top-level/all-packages.nix
··· 13410 13410 nvidia_x11_i686 = if system == "x86_64-linux" 13411 13411 then pkgsi686Linux.linuxPackages.nvidia_x11.override { libsOnly = true; } 13412 13412 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 13416 13415 else null; 13417 - }; 13418 - 13419 - # use if you intend to connect the nvidia card to a monitor 13420 - bumblebee_display = bumblebee.override { 13421 - useDisplayDevice = true; 13422 13416 }; 13423 13417 13424 13418 vkeybd = callPackage ../applications/audio/vkeybd {};