Author: amiddelk
Date: Sun Feb  5 00:51:35 2012
New Revision: 32036
URL: https://nixos.org/websvn/nix/?rev=32036&sc=1

Log:
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

Added:
   nixpkgs/trunk/pkgs/development/libraries/libbsd/
   nixpkgs/trunk/pkgs/development/libraries/libbsd/default.nix
   nixpkgs/trunk/pkgs/tools/X11/bumblebee/
   nixpkgs/trunk/pkgs/tools/X11/bumblebee/config.patch
   nixpkgs/trunk/pkgs/tools/X11/bumblebee/default.nix
   nixpkgs/trunk/pkgs/tools/X11/bumblebee/xopts.patch
   nixpkgs/trunk/pkgs/tools/X11/bumblebee/xorg.conf.nvidia
   nixpkgs/trunk/pkgs/tools/X11/virtualgl/fixturbopath.patch
Modified:
   nixpkgs/trunk/pkgs/development/libraries/libjpeg-turbo/default.nix
   nixpkgs/trunk/pkgs/tools/X11/virtualgl/default.nix
   nixpkgs/trunk/pkgs/top-level/all-packages.nix

Added: nixpkgs/trunk/pkgs/development/libraries/libbsd/default.nix
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/development/libraries/libbsd/default.nix Sun Feb  5 
00:51:35 2012        (r32036)
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl }:
+
+let name = "libbsd-0.3.0";
+in stdenv.mkDerivation {
+  inherit name;
+
+  src = fetchurl {
+    url = "http://libbsd.freedesktop.org/releases/${name}.tar.gz";;
+    sha256 = 
"fbf36ed40443e1d0d795adbae8d461952509e610c3ccf0866ae160b723f7fe38";
+  };
+
+  patchPhase = ''
+    substituteInPlace Makefile \
+      --replace "/usr" "$out" \
+      --replace "{exec_prefix}" "{prefix}"
+  '';
+
+  meta = { 
+    description = "Common functions found on BSD systems";
+    homepage = http://libbsd.freedesktop.org/;
+    license = "BSD3";
+  };
+}
+

Modified: nixpkgs/trunk/pkgs/development/libraries/libjpeg-turbo/default.nix
==============================================================================
--- nixpkgs/trunk/pkgs/development/libraries/libjpeg-turbo/default.nix  Sun Feb 
 5 00:43:54 2012        (r32035)
+++ nixpkgs/trunk/pkgs/development/libraries/libjpeg-turbo/default.nix  Sun Feb 
 5 00:51:35 2012        (r32036)
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, nasm }: 
 
 stdenv.mkDerivation {
-  name = "libjpeg-turbo-1.0.1";
+  name = "libjpeg-turbo-1.1.1";
   
   src = fetchurl {
-    url = mirror://sourceforge/libjpeg-turbo/libjpeg-turbo-1.0.1.tar.gz;
-    sha256 = "094jvqzibqbzmhh7mz3xi76lzlilxzb4j1x8rpdcdkzyig9dizqf";
+    url = mirror://sourceforge/libjpeg-turbo/libjpeg-turbo-1.1.1.tar.gz;
+    sha256 = 
"553b1f5a968fb9efc089623ed99be2aa6bc21586be92eb04848489c91a63f1e2";
   };
 
   buildInputs = [ nasm ];

Added: nixpkgs/trunk/pkgs/tools/X11/bumblebee/config.patch
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/tools/X11/bumblebee/config.patch Sun Feb  5 00:51:35 
2012        (r32036)
@@ -0,0 +1,30 @@
+--- bumblebee-3.0/src/driver.c.orig    2012-02-03 14:51:10.282464426 +0100
++++ bumblebee-3.0/src/driver.c 2012-02-04 22:26:02.715498536 +0100
+@@ -23,6 +23,7 @@
+ #include "module.h"
+ #include "bblogger.h"
+ #include "driver.h"
++#include <stdlib.h>
+ 
+ /**
+  * Check what drivers are available and autodetect if possible. Driver, module
+@@ -30,6 +31,7 @@
+  */
+ void driver_detect(void) {
+   /* determine driver to be used */
++  set_string_value(&bb_config.driver, getenv("BUMBLEBEE_DRIVER"));
+   if (*bb_config.driver) {
+     bb_log(LOG_DEBUG, "Skipping auto-detection, using configured driver"
+             " '%s'\n", bb_config.driver);
+@@ -65,8 +67,8 @@
+     }
+   }
+ 
+-  if (strcmp(bb_config.driver, "nvidia")) {
+-    set_string_value(&bb_config.ld_path, CONF_LDPATH_NVIDIA);
+-    set_string_value(&bb_config.mod_path, CONF_MODPATH_NVIDIA);
++  if (!strcmp(bb_config.driver, "nvidia")) {
++    set_string_value(&bb_config.ld_path, getenv("BUMBLEBEE_LDPATH_NVIDIA"));
++    set_string_value(&bb_config.mod_path, getenv("BUMBLEBEE_MODPATH_NVIDIA"));
+   }
+ }

Added: nixpkgs/trunk/pkgs/tools/X11/bumblebee/default.nix
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/tools/X11/bumblebee/default.nix  Sun Feb  5 00:51:35 
2012        (r32036)
@@ -0,0 +1,136 @@
+# The bumblebee package allows a program to be rendered on an
+# dedicated video card by spawning an additional X11 server
+# and streaming the results via VirtualGL to the primary server.
+
+# The package is rather chaotic; it's also quite recent.
+# As it may change a lot, some of the hacks in this nix expression
+# will hopefully not be needed in the future anymore.
+
+# To test: make sure that the 'bbswitch' kernel module is installed,
+# then run 'bumblebeed' as root and 'optirun glxgears' as user.
+# To use at startup, add e.g. to configuration.nix:
+# jobs = {
+#   bumblebeed = {
+#     name = "bumblebeed";
+#     description = "Manages the Optimus video card";
+#     startOn = "started udev and started syslogd";
+#     stopOn = "starting shutdown";
+#     exec = "bumblebeed --use-syslog";
+#     path = [ pkgs.bumblebee ];
+#     environment = { MODULE_DIR = "${config.system.modulesTree}/lib/modules"; 
};
+#     respawn = true;
+#   };
+# };
+
+# This nix expression supports for now only the native nvidia driver.
+# It should not be hard to generalize this approach to support the
+# nouveau driver as well (parameterize commonEnv over the module
+# package, and parameterize the two wrappers as well)
+
+{ stdenv, fetchurl, pkgconfig, help2man
+, libX11, glibc, gtkLibs, libbsd
+, makeWrapper, buildEnv, module_init_tools
+, linuxPackages, virtualgl, xorg, xkeyboard_config
+}:
+
+let
+  version = "3.0";
+  name = "bumblebee-${version}";
+
+  # isolated X11 environment with the nvidia module
+  # it should include all components needed for bumblebeed and
+  # optirun to spawn the second X server and to connect to it.
+  commonEnv = buildEnv {
+    name = "bumblebee-env";
+    paths = [
+      module_init_tools
+
+      linuxPackages.nvidia_x11
+      xorg.xorgserver
+      xorg.xrandr
+      xorg.xrdb
+      xorg.setxkbmap
+      xorg.libX11
+      xorg.libXext
+
+      virtualgl
+    ];
+
+    # the nvidia GLX module overwrites the one of xorgserver,
+    # thus nvidia_x11 must be before xorgserver in the paths.
+    ignoreCollisions = true;
+  };
+
+  # Custom X11 configuration for the additional xserver instance.
+  xorgConf = ./xorg.conf.nvidia;
+
+in stdenv.mkDerivation {
+  inherit name;
+
+  src = fetchurl {
+    url = 
"http://github.com/downloads/Bumblebee-Project/Bumblebee/${name}.tar.gz";;
+    sha256 = 
"a27ddb77b282ac8b972857fdb0dc5061cf0a0982b7ac3e1cfa698b4f786e49a1";
+  };
+
+  # 'config.patch' makes bumblebee read the active module and the nvidia 
configuration
+  # from the environment variables instead of the config file:
+  #   BUMBLEBEE_DRIVER, BUMBLEBEE_LDPATH_NVIDIA, BUMBLEBEE_MODPATH_NVIDIA
+  # These variables must be set when bumblebeed and optirun are executed.
+  patches = [ ./config.patch ./xopts.patch ];
+
+  preConfigure = ''
+    # Substitute the path to the actual modinfo program in module.c.
+    # Note: module.c also calls rmmod and modprobe, but those just have to
+    # be in PATH, and thus no action for them is required.
+    substituteInPlace src/module.c \
+      --replace "/sbin/modinfo" "${module_init_tools}/sbin/modinfo"
+
+    # Don't use a special group, just reuse wheel.
+    substituteInPlace configure \
+      --replace 'CONF_GID="bumblebee"' 'CONF_GID="wheel"'
+
+    # Ensures that the config file ends up with a nonempty
+    # name of the nvidia module. This is needed, because the
+    # configuration handling code otherwise resets the
+    # data that we obtained from the environment (see config.patch)
+    export CONF_DRIVER_MODULE_NVIDIA=nvidia
+  '';
+
+  # Build-time dependencies of bumblebeed and optirun.
+  # Note that it has several runtime dependencies.
+  buildInputs = [ stdenv makeWrapper pkgconfig help2man libX11 gtkLibs.glib 
libbsd ];
+
+  # create a wrapper environment for bumblebeed and optirun
+  postInstall = ''
+    # remove some entries from the configuration file that would otherwise
+    # cause our environment variables to be ignored.
+    substituteInPlace "$out/etc/bumblebee/bumblebee.conf" \
+      --replace "LibraryPath=" "" \
+      --replace "XorgModulePath=" ""
+
+    wrapProgram "$out/sbin/bumblebeed" \
+      --prefix PATH : "${commonEnv}/sbin:${commonEnv}/bin:\$PATH" \
+      --prefix LD_LIBRARY_PATH : "${commonEnv}/lib:\$LD_LIBRARY_PATH" \
+      --set BUMBLEBEE_DRIVER "nvidia" \
+      --set BUMBLEBEE_LDPATH_NVIDIA "${commonEnv}/lib" \
+      --set BUMBLEBEE_MODPATH_NVIDIA "${commonEnv}/lib/xorg/modules" \
+      --set FONTCONFIG_FILE "/etc/fonts/fonts.conf" \
+      --set XKB_BINDIR "${xorg.xkbcomp}/bin" \
+      --set XKB_DIR "${xkeyboard_config}/etc/X11/xkb"
+
+    wrapProgram "$out/bin/optirun" \
+      --prefix PATH : "${commonEnv}/sbin:${commonEnv}/bin" \
+      --prefix LD_LIBRARY_PATH : "${commonEnv}/lib" \
+      --set BUMBLEBEE_DRIVER "nvidia" \
+      --set BUMBLEBEE_LDPATH_NVIDIA "${commonEnv}/lib" \
+      --set BUMBLEBEE_MODPATH_NVIDIA "${commonEnv}/lib/xorg/modules"
+
+    cp ${xorgConf} "$out/etc/bumblebee/xorg.conf.nvidia"
+  '';
+
+  meta = {
+    homepage = http://github.com/Bumblebee-Project/Bumblebee;
+    description = "Daemon for managing Optimus videocards (power-on/off, 
spawns xservers)";
+    license = "free";
+  };
+}

Added: nixpkgs/trunk/pkgs/tools/X11/bumblebee/xopts.patch
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/tools/X11/bumblebee/xopts.patch  Sun Feb  5 00:51:35 
2012        (r32036)
@@ -0,0 +1,11 @@
+--- bumblebee-3.0/src/bbsecondary.c.orig       2012-02-05 00:03:06.003439638 
+0100
++++ bumblebee-3.0/src/bbsecondary.c    2012-02-05 00:46:38.017382619 +0100
+@@ -149,6 +149,8 @@
+       "-sharevts",
+       "-nolisten", "tcp",
+       "-noreset",
++      "-xkbdir", getenv("XKB_DIR"),
++      "-logfile", "/dev/null",
+       "-verbose", "3",
+       "-isolateDevice", pci_id,
+       "-modulepath",

Added: nixpkgs/trunk/pkgs/tools/X11/bumblebee/xorg.conf.nvidia
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/tools/X11/bumblebee/xorg.conf.nvidia     Sun Feb  5 
00:51:35 2012        (r32036)
@@ -0,0 +1,49 @@
+Section "DRI"
+    Mode 0666
+EndSection
+
+Section "ServerLayout"
+    Identifier "Layout0"
+    Screen "Screen1"
+    Option "AutoAddDevices" "false"
+EndSection
+
+Section "Module"
+    Load "dbe"
+    Load "extmod"
+    Load "glx"
+    Load "record"
+    Load "freetype"
+    Load "type1"
+EndSection
+
+Section "Files"
+EndSection
+
+Section "Device"
+    Identifier "Device1"
+    Driver "nvidia"
+    VendorName "NVIDIA Corporation"
+    Option "NoLogo" "true"
+    Option "UseEDID" "false"
+    Option "ConnectedMonitor" "CRT-0"
+EndSection
+
+Section "Screen"
+    Identifier "Screen1"
+    Device "Device1"
+    Monitor "Monitor0"
+    DefaultDepth 24
+    SubSection "Display"
+        Depth 24
+    EndSubSection
+EndSection
+
+Section "Extensions"
+    Option "Composite" "Enable"
+EndSection
+
+Section "Monitor"
+    Identifier "Monitor0"
+    Option "DPMS"
+EndSection

Modified: nixpkgs/trunk/pkgs/tools/X11/virtualgl/default.nix
==============================================================================
--- nixpkgs/trunk/pkgs/tools/X11/virtualgl/default.nix  Sun Feb  5 00:43:54 
2012        (r32035)
+++ nixpkgs/trunk/pkgs/tools/X11/virtualgl/default.nix  Sun Feb  5 00:51:35 
2012        (r32036)
@@ -1,4 +1,5 @@
-{stdenv, fetchurl, mesa, libX11, openssl, libXext, libjpeg_turbo}:
+{ stdenv, fetchurl, mesa, libX11, openssl, libXext
+, libjpeg_turbo, cmake }:
 
 let
   libDir = if stdenv.is64bit then "lib64" else "lib";
@@ -6,21 +7,23 @@
 stdenv.mkDerivation {
   name = "virtualgl-2.1.4";
   src = fetchurl {
-    url = mirror://sourceforge/virtualgl/VirtualGL-2.1.4.tar.gz;
-    sha256 = 
"d455e599620473a07711196615e59c73d08a7f392a9fcf60a6bc05d82809d89d";
+    url = mirror://sourceforge/virtualgl/VirtualGL-2.3.tar.gz;
+    sha256 = 
"2f00c4eb20b0ae88e957a23fb66882e4ade2faa208abd30aa8c4f61570ecd4b9";
   };
 
-  patches = [ ./xshm.patch ];
+  patches = [ ./xshm.patch ./fixturbopath.patch ];
 
   prePatch = ''
     sed -i s,LD_PRELOAD=lib,LD_PRELOAD=$out/${libDir}/lib, rr/vglrun
   '';
 
-  preInstall =''
+  cmakeFlags = [ "-DTJPEG_LIBRARY=${libjpeg_turbo}/lib/libturbojpeg.so" ];
+
+  preInstall = ''
     export makeFlags="prefix=$out"
   '';
 
-  buildInputs = [ mesa libX11 openssl libXext libjpeg_turbo ];
+  buildInputs = [ cmake mesa libX11 openssl libXext libjpeg_turbo ];
 
   meta = {
     homepage = http://www.virtualgl.org/;

Added: nixpkgs/trunk/pkgs/tools/X11/virtualgl/fixturbopath.patch
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/tools/X11/virtualgl/fixturbopath.patch   Sun Feb  5 
00:51:35 2012        (r32036)
@@ -0,0 +1,16 @@
+--- VirtualGL-2.3/cmakescripts/FindTurboJPEG.cmake.orig 2012-02-02 
17:33:49.496283001 +0100
++++ VirtualGL-2.3/cmakescripts/FindTurboJPEG.cmake      2012-02-02 
17:44:18.772483239 +0100
+@@ -40,8 +40,11 @@
+        endif()
+ endif()
+ 
+-set(TJPEG_LIBRARY ${DEFAULT_TJPEG_LIBRARY} CACHE PATH
+-  "TurboJPEG library path (default: ${DEFAULT_TJPEG_LIBRARY})")
++if(NOT TJPEG_LIBRARY)
++       message(STATUS "TJPEG_LIBRARY environment variable not set")
++       set(TJPEG_LIBRARY ${DEFAULT_TJPEG_LIBRARY} CACHE PATH
++               "TurboJPEG library path (default: ${DEFAULT_TJPEG_LIBRARY})")
++endif()
+ 
+ if(WIN32)
+        set(CMAKE_REQUIRED_DEFINITIONS -MT)

Modified: nixpkgs/trunk/pkgs/top-level/all-packages.nix
==============================================================================
--- nixpkgs/trunk/pkgs/top-level/all-packages.nix       Sun Feb  5 00:43:54 
2012        (r32035)
+++ nixpkgs/trunk/pkgs/top-level/all-packages.nix       Sun Feb  5 00:51:35 
2012        (r32036)
@@ -680,6 +680,8 @@
 
   flvstreamer = callPackage ../tools/networking/flvstreamer { };
 
+  libbsd = callPackage ../development/libraries/libbsd { };
+
   flvtool2 = callPackage ../tools/video/flvtool2 { };
 
   fontforge = callPackage ../tools/misc/fontforge { };
@@ -7682,6 +7684,8 @@
 
   virtualgl = callPackage ../tools/X11/virtualgl { };
 
+  bumblebee = callPackage ../tools/X11/bumblebee { };
+
   vkeybd = callPackage ../applications/audio/vkeybd {
     inherit (xlibs) libX11;
   };
_______________________________________________
nix-commits mailing list
nix-comm...@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to