2012-02-05 00:51:35 +00:00
|
|
|
# The bumblebee package allows a program to be rendered on an
|
2014-05-03 15:28:21 +01:00
|
|
|
# dedicated video card by spawning an additional X11 server and
|
|
|
|
# streaming the results via VirtualGL or primus to the primary server.
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2014-05-03 15:28:21 +01:00
|
|
|
# To test:
|
|
|
|
# 1. make sure that the 'bbswitch' kernel module is installed,
|
|
|
|
# 2. then run 'bumblebeed' as root
|
|
|
|
# 3. Then either 'optirun glxinfo' or 'primusrun glxinfo' as user.
|
|
|
|
#
|
|
|
|
# The glxinfo output should indicate the NVidia driver is being used
|
|
|
|
# and all expected extensions are supported.
|
|
|
|
#
|
2014-02-08 18:47:51 +00:00
|
|
|
# To use at startup, see hardware.bumblebee options.
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
# This nix expression supports for now only the native nvidia driver.
|
|
|
|
# It should not be hard to generalize this approach to support the
|
2014-05-03 15:28:21 +01:00
|
|
|
# nouveau driver as well (parameterize hostEnv, i686Env over the
|
|
|
|
# module package, and parameterize the two wrappers as well)
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
{ stdenv, fetchurl, pkgconfig, help2man
|
2012-03-14 21:57:32 +00:00
|
|
|
, libX11, glibc, glib, libbsd
|
2012-02-05 00:51:35 +00:00
|
|
|
, makeWrapper, buildEnv, module_init_tools
|
2014-05-03 15:28:21 +01:00
|
|
|
, xorg, xkeyboard_config
|
|
|
|
, nvidia_x11, virtualgl
|
|
|
|
# The below should only be non-null in a x86_64 system. On a i686
|
|
|
|
# system the above nvidia_x11 and virtualgl will be the i686 packages.
|
|
|
|
# TODO: Confusing. Perhaps use "SubArch" instead of i686?
|
|
|
|
, nvidia_x11_i686 ? null
|
|
|
|
, virtualgl_i686 ? null
|
2014-12-20 10:51:24 +00:00
|
|
|
, useDisplayDevice ? false
|
|
|
|
, extraDeviceOptions ? ""
|
2012-02-05 00:51:35 +00:00
|
|
|
}:
|
2014-05-03 15:28:21 +01:00
|
|
|
with stdenv.lib;
|
2012-02-05 00:51:35 +00:00
|
|
|
let
|
2014-02-08 18:47:51 +00:00
|
|
|
version = "3.2.1";
|
2012-02-05 00:51:35 +00:00
|
|
|
name = "bumblebee-${version}";
|
|
|
|
|
2014-05-03 15:28:21 +01:00
|
|
|
# Isolated X11 environment without the acceleration driver module.
|
|
|
|
# Includes the rest of the components needed for bumblebeed and
|
2012-02-05 00:51:35 +00:00
|
|
|
# optirun to spawn the second X server and to connect to it.
|
2014-05-03 15:28:21 +01:00
|
|
|
x11Env = buildEnv {
|
2012-02-05 00:51:35 +00:00
|
|
|
name = "bumblebee-env";
|
|
|
|
paths = [
|
|
|
|
module_init_tools
|
|
|
|
xorg.xorgserver
|
|
|
|
xorg.xrandr
|
|
|
|
xorg.xrdb
|
|
|
|
xorg.setxkbmap
|
|
|
|
xorg.libX11
|
|
|
|
xorg.libXext
|
2014-05-03 15:28:21 +01:00
|
|
|
xorg.xf86inputevdev
|
|
|
|
];
|
|
|
|
};
|
2012-02-05 00:51:35 +00:00
|
|
|
|
2014-05-03 15:28:21 +01:00
|
|
|
# The environment for the host architecture.
|
|
|
|
hostEnv = buildEnv {
|
|
|
|
name = "bumblebee-x64-env";
|
|
|
|
paths = [
|
|
|
|
nvidia_x11
|
2012-02-05 00:51:35 +00:00
|
|
|
virtualgl
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2014-05-03 15:28:21 +01:00
|
|
|
# The environment for the sub architecture, i686, if there is one
|
|
|
|
i686Env = if virtualgl_i686 != null
|
|
|
|
then buildEnv {
|
|
|
|
name = "bumblebee-i686-env";
|
|
|
|
paths = [
|
|
|
|
nvidia_x11_i686
|
|
|
|
virtualgl_i686
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else null;
|
|
|
|
|
|
|
|
allEnvs = [hostEnv] ++ optional (i686Env != null) i686Env;
|
|
|
|
ldPathString = makeLibraryPath allEnvs;
|
|
|
|
|
2014-12-20 10:51:24 +00:00
|
|
|
# By default we don't want to use a display device
|
|
|
|
deviceOptions = if useDisplayDevice
|
|
|
|
then ""
|
|
|
|
else ''
|
|
|
|
|
|
|
|
# Disable display device
|
|
|
|
Option "UseEDID" "false"
|
|
|
|
Option "UseDisplayDevice" "none"
|
|
|
|
''
|
|
|
|
+ extraDeviceOptions;
|
|
|
|
|
2012-02-05 00:51:35 +00:00
|
|
|
in stdenv.mkDerivation {
|
2014-12-20 10:51:24 +00:00
|
|
|
inherit name deviceOptions;
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2014-02-08 18:47:51 +00:00
|
|
|
url = "http://bumblebee-project.org/${name}.tar.gz";
|
|
|
|
sha256 = "03p3gvx99lwlavznrpg9l7jnl1yfg2adcj8jcjj0gxp20wxp060h";
|
2012-02-05 00:51:35 +00:00
|
|
|
};
|
|
|
|
|
2014-12-20 10:51:24 +00:00
|
|
|
patches = [ ./xopts.patch ./nvidia-conf.patch];
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
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.
|
2014-05-03 15:28:21 +01:00
|
|
|
|
2012-02-05 00:51:35 +00:00
|
|
|
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"'
|
2014-12-20 10:51:24 +00:00
|
|
|
|
|
|
|
# Apply configuration options
|
|
|
|
substituteInPlace conf/xorg.conf.nvidia \
|
|
|
|
--subst-var deviceOptions
|
2012-02-05 00:51:35 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Build-time dependencies of bumblebeed and optirun.
|
|
|
|
# Note that it has several runtime dependencies.
|
2012-03-14 21:57:32 +00:00
|
|
|
buildInputs = [ stdenv makeWrapper pkgconfig help2man libX11 glib libbsd ];
|
2012-02-05 00:51:35 +00:00
|
|
|
|
2014-05-03 15:28:21 +01:00
|
|
|
# The order of LDPATH is very specific: First X11 then the host
|
|
|
|
# environment then the optional sub architecture paths.
|
|
|
|
#
|
|
|
|
# The order for MODPATH is the opposite: First the environment that
|
|
|
|
# includes the acceleration driver. As this is used for the X11
|
|
|
|
# server, which runs under the host architecture, this does not
|
|
|
|
# include the sub architecture components.
|
2014-02-08 18:47:51 +00:00
|
|
|
configureFlags = [
|
|
|
|
"--with-udev-rules=$out/lib/udev/rules.d"
|
|
|
|
"CONF_DRIVER=nvidia"
|
|
|
|
"CONF_DRIVER_MODULE_NVIDIA=nvidia"
|
2014-05-03 15:28:21 +01:00
|
|
|
"CONF_LDPATH_NVIDIA=${x11Env}/lib:${ldPathString}"
|
|
|
|
"CONF_MODPATH_NVIDIA=${hostEnv}/lib/xorg/modules,${x11Env}/lib/xorg/modules"
|
2014-02-08 18:47:51 +00:00
|
|
|
];
|
|
|
|
|
2012-02-05 00:51:35 +00:00
|
|
|
# create a wrapper environment for bumblebeed and optirun
|
|
|
|
postInstall = ''
|
|
|
|
wrapProgram "$out/sbin/bumblebeed" \
|
2014-05-03 15:28:21 +01:00
|
|
|
--prefix PATH : "${x11Env}/sbin:${x11Env}/bin:${hostEnv}/bin:\$PATH" \
|
|
|
|
--prefix LD_LIBRARY_PATH : "${x11Env}/lib:${hostEnv}/lib:\$LD_LIBRARY_PATH" \
|
|
|
|
--set FONTCONFIG_FILE "/etc/fonts/fonts.conf" \
|
2012-02-05 00:51:35 +00:00
|
|
|
--set XKB_BINDIR "${xorg.xkbcomp}/bin" \
|
|
|
|
--set XKB_DIR "${xkeyboard_config}/etc/X11/xkb"
|
|
|
|
|
|
|
|
wrapProgram "$out/bin/optirun" \
|
2014-05-03 15:28:21 +01:00
|
|
|
--prefix PATH : "${hostEnv}/bin"
|
|
|
|
'' + (if i686Env == null
|
|
|
|
then ""
|
|
|
|
else ''
|
|
|
|
makeWrapper "$out/bin/.optirun-wrapped" "$out/bin/optirun32" \
|
|
|
|
--prefix PATH : "${i686Env}/bin"
|
|
|
|
'');
|
2012-02-05 00:51:35 +00:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
homepage = http://github.com/Bumblebee-Project/Bumblebee;
|
|
|
|
description = "Daemon for managing Optimus videocards (power-on/off, spawns xservers)";
|
2014-02-08 18:47:51 +00:00
|
|
|
license = stdenv.lib.licenses.gpl3;
|
2012-02-05 00:51:35 +00:00
|
|
|
};
|
|
|
|
}
|