Added 'bumblebee', a package that facilitates NVidia Optimus graphics with X11.

Note: it relies heavily on 'virtualgl'. This also makes the approach taken
by bumblebee not very effective.
So, this package is actually mainly useful for shutting down your card so that
it does not consume power/produce heat.

See the comments in bumblebee/default.nix

svn path=/nixpkgs/trunk/; revision=32036

+282 -9
+24
pkgs/development/libraries/libbsd/default.nix
··· 1 + { stdenv, fetchurl }: 2 + 3 + let name = "libbsd-0.3.0"; 4 + in stdenv.mkDerivation { 5 + inherit name; 6 + 7 + src = fetchurl { 8 + url = "http://libbsd.freedesktop.org/releases/${name}.tar.gz"; 9 + sha256 = "fbf36ed40443e1d0d795adbae8d461952509e610c3ccf0866ae160b723f7fe38"; 10 + }; 11 + 12 + patchPhase = '' 13 + substituteInPlace Makefile \ 14 + --replace "/usr" "$out" \ 15 + --replace "{exec_prefix}" "{prefix}" 16 + ''; 17 + 18 + meta = { 19 + description = "Common functions found on BSD systems"; 20 + homepage = http://libbsd.freedesktop.org/; 21 + license = "BSD3"; 22 + }; 23 + } 24 +
+3 -3
pkgs/development/libraries/libjpeg-turbo/default.nix
··· 1 1 { stdenv, fetchurl, nasm }: 2 2 3 3 stdenv.mkDerivation { 4 - name = "libjpeg-turbo-1.0.1"; 4 + name = "libjpeg-turbo-1.1.1"; 5 5 6 6 src = fetchurl { 7 - url = mirror://sourceforge/libjpeg-turbo/libjpeg-turbo-1.0.1.tar.gz; 8 - sha256 = "094jvqzibqbzmhh7mz3xi76lzlilxzb4j1x8rpdcdkzyig9dizqf"; 7 + url = mirror://sourceforge/libjpeg-turbo/libjpeg-turbo-1.1.1.tar.gz; 8 + sha256 = "553b1f5a968fb9efc089623ed99be2aa6bc21586be92eb04848489c91a63f1e2"; 9 9 }; 10 10 11 11 buildInputs = [ nasm ];
+30
pkgs/tools/X11/bumblebee/config.patch
··· 1 + --- bumblebee-3.0/src/driver.c.orig 2012-02-03 14:51:10.282464426 +0100 2 + +++ bumblebee-3.0/src/driver.c 2012-02-04 22:26:02.715498536 +0100 3 + @@ -23,6 +23,7 @@ 4 + #include "module.h" 5 + #include "bblogger.h" 6 + #include "driver.h" 7 + +#include <stdlib.h> 8 + 9 + /** 10 + * Check what drivers are available and autodetect if possible. Driver, module 11 + @@ -30,6 +31,7 @@ 12 + */ 13 + void driver_detect(void) { 14 + /* determine driver to be used */ 15 + + set_string_value(&bb_config.driver, getenv("BUMBLEBEE_DRIVER")); 16 + if (*bb_config.driver) { 17 + bb_log(LOG_DEBUG, "Skipping auto-detection, using configured driver" 18 + " '%s'\n", bb_config.driver); 19 + @@ -65,8 +67,8 @@ 20 + } 21 + } 22 + 23 + - if (strcmp(bb_config.driver, "nvidia")) { 24 + - set_string_value(&bb_config.ld_path, CONF_LDPATH_NVIDIA); 25 + - set_string_value(&bb_config.mod_path, CONF_MODPATH_NVIDIA); 26 + + if (!strcmp(bb_config.driver, "nvidia")) { 27 + + set_string_value(&bb_config.ld_path, getenv("BUMBLEBEE_LDPATH_NVIDIA")); 28 + + set_string_value(&bb_config.mod_path, getenv("BUMBLEBEE_MODPATH_NVIDIA")); 29 + } 30 + }
+136
pkgs/tools/X11/bumblebee/default.nix
··· 1 + # The bumblebee package allows a program to be rendered on an 2 + # dedicated video card by spawning an additional X11 server 3 + # and streaming the results via VirtualGL to the primary server. 4 + 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. 8 + 9 + # To test: make sure that the 'bbswitch' kernel module is installed, 10 + # then run 'bumblebeed' as root and 'optirun glxgears' as user. 11 + # To use at startup, add e.g. to configuration.nix: 12 + # jobs = { 13 + # bumblebeed = { 14 + # name = "bumblebeed"; 15 + # description = "Manages the Optimus video card"; 16 + # startOn = "started udev and started syslogd"; 17 + # stopOn = "starting shutdown"; 18 + # exec = "bumblebeed --use-syslog"; 19 + # path = [ pkgs.bumblebee ]; 20 + # environment = { MODULE_DIR = "${config.system.modulesTree}/lib/modules"; }; 21 + # respawn = true; 22 + # }; 23 + # }; 24 + 25 + # This nix expression supports for now only the native nvidia driver. 26 + # It should not be hard to generalize this approach to support the 27 + # nouveau driver as well (parameterize commonEnv over the module 28 + # package, and parameterize the two wrappers as well) 29 + 30 + { stdenv, fetchurl, pkgconfig, help2man 31 + , libX11, glibc, gtkLibs, libbsd 32 + , makeWrapper, buildEnv, module_init_tools 33 + , linuxPackages, virtualgl, xorg, xkeyboard_config 34 + }: 35 + 36 + let 37 + version = "3.0"; 38 + name = "bumblebee-${version}"; 39 + 40 + # isolated X11 environment with the nvidia module 41 + # it should include all components needed for bumblebeed and 42 + # optirun to spawn the second X server and to connect to it. 43 + commonEnv = buildEnv { 44 + name = "bumblebee-env"; 45 + paths = [ 46 + module_init_tools 47 + 48 + linuxPackages.nvidia_x11 49 + xorg.xorgserver 50 + xorg.xrandr 51 + xorg.xrdb 52 + xorg.setxkbmap 53 + xorg.libX11 54 + xorg.libXext 55 + 56 + virtualgl 57 + ]; 58 + 59 + # the nvidia GLX module overwrites the one of xorgserver, 60 + # thus nvidia_x11 must be before xorgserver in the paths. 61 + ignoreCollisions = true; 62 + }; 63 + 64 + # Custom X11 configuration for the additional xserver instance. 65 + xorgConf = ./xorg.conf.nvidia; 66 + 67 + in stdenv.mkDerivation { 68 + inherit name; 69 + 70 + src = fetchurl { 71 + url = "http://github.com/downloads/Bumblebee-Project/Bumblebee/${name}.tar.gz"; 72 + sha256 = "a27ddb77b282ac8b972857fdb0dc5061cf0a0982b7ac3e1cfa698b4f786e49a1"; 73 + }; 74 + 75 + # 'config.patch' makes bumblebee read the active module and the nvidia configuration 76 + # from the environment variables instead of the config file: 77 + # BUMBLEBEE_DRIVER, BUMBLEBEE_LDPATH_NVIDIA, BUMBLEBEE_MODPATH_NVIDIA 78 + # These variables must be set when bumblebeed and optirun are executed. 79 + patches = [ ./config.patch ./xopts.patch ]; 80 + 81 + preConfigure = '' 82 + # Substitute the path to the actual modinfo program in module.c. 83 + # Note: module.c also calls rmmod and modprobe, but those just have to 84 + # be in PATH, and thus no action for them is required. 85 + substituteInPlace src/module.c \ 86 + --replace "/sbin/modinfo" "${module_init_tools}/sbin/modinfo" 87 + 88 + # Don't use a special group, just reuse wheel. 89 + substituteInPlace configure \ 90 + --replace 'CONF_GID="bumblebee"' 'CONF_GID="wheel"' 91 + 92 + # Ensures that the config file ends up with a nonempty 93 + # name of the nvidia module. This is needed, because the 94 + # configuration handling code otherwise resets the 95 + # data that we obtained from the environment (see config.patch) 96 + export CONF_DRIVER_MODULE_NVIDIA=nvidia 97 + ''; 98 + 99 + # Build-time dependencies of bumblebeed and optirun. 100 + # Note that it has several runtime dependencies. 101 + buildInputs = [ stdenv makeWrapper pkgconfig help2man libX11 gtkLibs.glib libbsd ]; 102 + 103 + # create a wrapper environment for bumblebeed and optirun 104 + postInstall = '' 105 + # remove some entries from the configuration file that would otherwise 106 + # cause our environment variables to be ignored. 107 + substituteInPlace "$out/etc/bumblebee/bumblebee.conf" \ 108 + --replace "LibraryPath=" "" \ 109 + --replace "XorgModulePath=" "" 110 + 111 + wrapProgram "$out/sbin/bumblebeed" \ 112 + --prefix PATH : "${commonEnv}/sbin:${commonEnv}/bin:\$PATH" \ 113 + --prefix LD_LIBRARY_PATH : "${commonEnv}/lib:\$LD_LIBRARY_PATH" \ 114 + --set BUMBLEBEE_DRIVER "nvidia" \ 115 + --set BUMBLEBEE_LDPATH_NVIDIA "${commonEnv}/lib" \ 116 + --set BUMBLEBEE_MODPATH_NVIDIA "${commonEnv}/lib/xorg/modules" \ 117 + --set FONTCONFIG_FILE "/etc/fonts/fonts.conf" \ 118 + --set XKB_BINDIR "${xorg.xkbcomp}/bin" \ 119 + --set XKB_DIR "${xkeyboard_config}/etc/X11/xkb" 120 + 121 + wrapProgram "$out/bin/optirun" \ 122 + --prefix PATH : "${commonEnv}/sbin:${commonEnv}/bin" \ 123 + --prefix LD_LIBRARY_PATH : "${commonEnv}/lib" \ 124 + --set BUMBLEBEE_DRIVER "nvidia" \ 125 + --set BUMBLEBEE_LDPATH_NVIDIA "${commonEnv}/lib" \ 126 + --set BUMBLEBEE_MODPATH_NVIDIA "${commonEnv}/lib/xorg/modules" 127 + 128 + cp ${xorgConf} "$out/etc/bumblebee/xorg.conf.nvidia" 129 + ''; 130 + 131 + meta = { 132 + homepage = http://github.com/Bumblebee-Project/Bumblebee; 133 + description = "Daemon for managing Optimus videocards (power-on/off, spawns xservers)"; 134 + license = "free"; 135 + }; 136 + }
+11
pkgs/tools/X11/bumblebee/xopts.patch
··· 1 + --- bumblebee-3.0/src/bbsecondary.c.orig 2012-02-05 00:03:06.003439638 +0100 2 + +++ bumblebee-3.0/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", "/dev/null", 9 + "-verbose", "3", 10 + "-isolateDevice", pci_id, 11 + "-modulepath",
+49
pkgs/tools/X11/bumblebee/xorg.conf.nvidia
··· 1 + Section "DRI" 2 + Mode 0666 3 + EndSection 4 + 5 + Section "ServerLayout" 6 + Identifier "Layout0" 7 + Screen "Screen1" 8 + Option "AutoAddDevices" "false" 9 + EndSection 10 + 11 + Section "Module" 12 + Load "dbe" 13 + Load "extmod" 14 + Load "glx" 15 + Load "record" 16 + Load "freetype" 17 + Load "type1" 18 + EndSection 19 + 20 + Section "Files" 21 + EndSection 22 + 23 + Section "Device" 24 + Identifier "Device1" 25 + Driver "nvidia" 26 + VendorName "NVIDIA Corporation" 27 + Option "NoLogo" "true" 28 + Option "UseEDID" "false" 29 + Option "ConnectedMonitor" "CRT-0" 30 + EndSection 31 + 32 + Section "Screen" 33 + Identifier "Screen1" 34 + Device "Device1" 35 + Monitor "Monitor0" 36 + DefaultDepth 24 37 + SubSection "Display" 38 + Depth 24 39 + EndSubSection 40 + EndSection 41 + 42 + Section "Extensions" 43 + Option "Composite" "Enable" 44 + EndSection 45 + 46 + Section "Monitor" 47 + Identifier "Monitor0" 48 + Option "DPMS" 49 + EndSection
+9 -6
pkgs/tools/X11/virtualgl/default.nix
··· 1 - {stdenv, fetchurl, mesa, libX11, openssl, libXext, libjpeg_turbo}: 1 + { stdenv, fetchurl, mesa, libX11, openssl, libXext 2 + , libjpeg_turbo, cmake }: 2 3 3 4 let 4 5 libDir = if stdenv.is64bit then "lib64" else "lib"; ··· 6 7 stdenv.mkDerivation { 7 8 name = "virtualgl-2.1.4"; 8 9 src = fetchurl { 9 - url = mirror://sourceforge/virtualgl/VirtualGL-2.1.4.tar.gz; 10 - sha256 = "d455e599620473a07711196615e59c73d08a7f392a9fcf60a6bc05d82809d89d"; 10 + url = mirror://sourceforge/virtualgl/VirtualGL-2.3.tar.gz; 11 + sha256 = "2f00c4eb20b0ae88e957a23fb66882e4ade2faa208abd30aa8c4f61570ecd4b9"; 11 12 }; 12 13 13 - patches = [ ./xshm.patch ]; 14 + patches = [ ./xshm.patch ./fixturbopath.patch ]; 14 15 15 16 prePatch = '' 16 17 sed -i s,LD_PRELOAD=lib,LD_PRELOAD=$out/${libDir}/lib, rr/vglrun 17 18 ''; 18 19 19 - preInstall ='' 20 + cmakeFlags = [ "-DTJPEG_LIBRARY=${libjpeg_turbo}/lib/libturbojpeg.so" ]; 21 + 22 + preInstall = '' 20 23 export makeFlags="prefix=$out" 21 24 ''; 22 25 23 - buildInputs = [ mesa libX11 openssl libXext libjpeg_turbo ]; 26 + buildInputs = [ cmake mesa libX11 openssl libXext libjpeg_turbo ]; 24 27 25 28 meta = { 26 29 homepage = http://www.virtualgl.org/;
+16
pkgs/tools/X11/virtualgl/fixturbopath.patch
··· 1 + --- VirtualGL-2.3/cmakescripts/FindTurboJPEG.cmake.orig 2012-02-02 17:33:49.496283001 +0100 2 + +++ VirtualGL-2.3/cmakescripts/FindTurboJPEG.cmake 2012-02-02 17:44:18.772483239 +0100 3 + @@ -40,8 +40,11 @@ 4 + endif() 5 + endif() 6 + 7 + -set(TJPEG_LIBRARY ${DEFAULT_TJPEG_LIBRARY} CACHE PATH 8 + - "TurboJPEG library path (default: ${DEFAULT_TJPEG_LIBRARY})") 9 + +if(NOT TJPEG_LIBRARY) 10 + + message(STATUS "TJPEG_LIBRARY environment variable not set") 11 + + set(TJPEG_LIBRARY ${DEFAULT_TJPEG_LIBRARY} CACHE PATH 12 + + "TurboJPEG library path (default: ${DEFAULT_TJPEG_LIBRARY})") 13 + +endif() 14 + 15 + if(WIN32) 16 + set(CMAKE_REQUIRED_DEFINITIONS -MT)
+4
pkgs/top-level/all-packages.nix
··· 680 680 681 681 flvstreamer = callPackage ../tools/networking/flvstreamer { }; 682 682 683 + libbsd = callPackage ../development/libraries/libbsd { }; 684 + 683 685 flvtool2 = callPackage ../tools/video/flvtool2 { }; 684 686 685 687 fontforge = callPackage ../tools/misc/fontforge { }; ··· 7681 7683 virtviewer = callPackage ../applications/virtualization/virt-viewer {}; 7682 7684 7683 7685 virtualgl = callPackage ../tools/X11/virtualgl { }; 7686 + 7687 + bumblebee = callPackage ../tools/X11/bumblebee { }; 7684 7688 7685 7689 vkeybd = callPackage ../applications/audio/vkeybd { 7686 7690 inherit (xlibs) libX11;