1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-09-11 15:08:33 +01:00

My attempt to get Steam working in NixOS. It uses a function called buildFHSChrootEnv {} that composed chroot environments. In such a chroot environment, I could run Steam without much problem

This commit is contained in:
Sander van der Burg 2013-09-13 23:58:59 +02:00
parent e67a2479e1
commit 28d8e93871
9 changed files with 236 additions and 1 deletions

View file

@ -0,0 +1,84 @@
{stdenv, glibc, glibcLocales, gcc, coreutils, diffutils, findutils, gnused, gnugrep, gnutar, gzip, bzip2,
bashInteractive, xz, shadow, gawk, less, buildEnv}:
{name, pkgs ? [], profile ? ""}:
let
basePkgs = [ glibc glibcLocales gcc coreutils diffutils findutils gnused gnugrep gnutar gzip bzip2
bashInteractive xz shadow gawk less ];
# Compose a global profile for the chroot environment
profilePkg = stdenv.mkDerivation {
name = "${name}-chrootenv-profile";
buildCommand = ''
mkdir -p $out/etc
cat >> $out/etc/profile << "EOF"
export PS1='${name}-chrootenv:\u@\h:\w\$ '
${profile}
EOF
'';
};
paths = basePkgs ++ [ profilePkg ] ++ pkgs;
# Composes a /usr like directory structure
staticUsrProfile = buildEnv {
name = "system-profile";
inherit paths;
};
# References to shell scripts that set up or tear down the environment
initSh = ./init.sh.in;
mountSh = ./mount.sh.in;
loadSh = ./load.sh.in;
umountSh = ./umount.sh.in;
destroySh = ./destroy.sh.in;
in
stdenv.mkDerivation {
name = "${name}-chrootenv";
buildCommand = ''
mkdir -p $out/sw
cd $out/sw
for i in ${staticUsrProfile}/{etc,bin,lib{,32,64},sbin,var}
do
if [ -x "$i" ]
then
ln -s "$i"
fi
done
ln -s ${staticUsrProfile} usr
cd ..
mkdir -p bin
cd bin
sed -e "s|@chrootEnv@|$out|g" \
-e "s|@name@|${name}|g" \
-e "s|@shell@|${stdenv.shell}|g" \
${initSh} > init-${name}-chrootenv
chmod +x init-${name}-chrootenv
sed -e "s|@shell@|${stdenv.shell}|g" \
-e "s|@name@|${name}|g" \
${mountSh} > mount-${name}-chrootenv
chmod +x mount-${name}-chrootenv
sed -e "s|@shell@|${stdenv.shell}|g" \
-e "s|@name@|${name}|g" \
${loadSh} > load-${name}-chrootenv
chmod +x load-${name}-chrootenv
sed -e "s|@shell@|${stdenv.shell}|g" \
-e "s|@name@|${name}|g" \
${umountSh} > umount-${name}-chrootenv
chmod +x umount-${name}-chrootenv
sed -e "s|@chrootEnv@|$out|g" \
-e "s|@shell@|${stdenv.shell}|g" \
-e "s|@name@|${name}|g" \
${destroySh} > destroy-${name}-chrootenv
chmod +x destroy-${name}-chrootenv
'';
}

View file

@ -0,0 +1,21 @@
#! @shell@ -e
chrootenvDest=/run/chrootenv/@name@
# Remove bind mount points
rmdir $chrootenvDest/{dev,nix/store,nix,proc,sys,host-etc,home,var,run}
# Remove symlinks to the software that should be part of the chroot system profile
for i in @chrootEnv@/sw/*
do
if [ "$i" != "@chrootEnv@/sw/etc" ] && [ "$i" != "@chrootEnv@/sw/var" ]
then
rm $chrootenvDest/$(basename $i)
fi
done
# Remove the remaining folders
rm -Rf $chrootenvDest/{etc,root,tmp}
# Remove the chroot environment folder
rmdir $chrootenvDest

View file

@ -0,0 +1,48 @@
#! @shell@ -e
chrootenvDest=/run/chrootenv/@name@
# Create some mount points for stuff that must be bind mounted
mkdir -p $chrootenvDest/{nix/store,dev,proc,sys,host-etc,home,var,run}
# Symlink the software that should be part of the chroot system profile
for i in @chrootEnv@/sw/*
do
if [ "$i" != "@chrootEnv@/sw/etc" ] && [ "$i" != "@chrootEnv@/sw/var" ]
then
ln -s "$i" "$chrootenvDest"
fi
done
# Symlink the contents of the chroot software's /etc
mkdir $chrootenvDest/etc
for i in @chrootEnv@/sw/etc/*
do
ln -s "$i" $chrootenvDest/etc
done
# Symlink some NSS stuff
ln -s ../host-etc/passwd $chrootenvDest/etc/passwd
ln -s ../host-etc/group $chrootenvDest/etc/group
ln -s ../host-etc/shadow $chrootenvDest/etc/shadow
ln -s ../host-etc/hosts $chrootenvDest/etc/hosts
ln -s ../host-etc/resolv.conf $chrootenvDest/etc/resolv.conf
ln -s ../host-etc/nsswitch.conf $chrootenvDest/etc/nsswitch.conf
# Symlink PAM stuff
rm $chrootenvDest/etc/pam.d
ln -s ../host-etc/static/pam.d $chrootenvDest/etc/pam.d
# Symlink Font stuff
mkdir $chrootenvDest/etc/fonts
ln -s ../../host-etc/static/fonts/fonts.conf $chrootenvDest/etc/fonts
mkdir $chrootenvDest/etc/fonts/conf.d
ln -s ../../../host-etc/static/fonts/conf.d/00-nixos.conf $chrootenvDest/etc/fonts/conf.d
# Create root folder
mkdir $chrootenvDest/root
# Create tmp folder
mkdir -m1777 $chrootenvDest/tmp

View file

@ -0,0 +1,6 @@
#! @shell@ -e
chrootenvDest=/run/chrootenv/@name@
# Enter the LFS chroot environment
chroot $chrootenvDest /usr/bin/env -i PS1="$PS1" TERM="$TERM" DISPLAY="$DISPLAY" HOME="/root" PATH="/bin:/sbin" /bin/bash --login

View file

@ -0,0 +1,23 @@
#! @shell@ -e
chrootenvDest=/run/chrootenv/@name@
# Bind mount the Nix store
mount --bind /nix/store $chrootenvDest/nix/store
# Bind mount some kernel related stuff
mount --bind /dev $chrootenvDest/dev
mount --bind /dev/pts $chrootenvDest/dev/pts
mount --bind /dev/shm $chrootenvDest/dev/shm
mount --bind /proc $chrootenvDest/proc
mount --bind /sys $chrootenvDest/sys
# Bind mount home directories
mount --bind /home $chrootenvDest/home
# Bind mount state directories
mount --bind /var $chrootenvDest/var
mount --bind /run $chrootenvDest/run
# Bind mount the host system's /etc
mount --bind /etc $chrootenvDest/host-etc

View file

@ -0,0 +1,6 @@
#! @shell@ -e
chrootenvDest=/run/chrootenv/@name@
# Unmount all bind mounts
umount $chrootenvDest/{dev/pts,dev/shm,dev,nix/store,proc,sys,host-etc,home,var,run}

View file

@ -0,0 +1,12 @@
{ buildFHSChrootEnv, steam
, xterm, libX11, zenity, python, mesa, xdg_utils, dbus_tools, alsaLib
}:
buildFHSChrootEnv {
name = "steam";
pkgs = [ steam xterm libX11 zenity python mesa xdg_utils dbus_tools alsaLib ];
profile = ''
export LD_LIBRARY_PATH=/run/opengl-driver/lib:/run/opengl-driver-32/lib:/lib
export FONTCONFIG_FILE=/etc/fonts/fonts.conf
'';
}

View file

@ -1,4 +1,4 @@
{ stdenv, fetchurl, dpkg, makeWrapper, xz, libX11, gcc, glibc
/*{ stdenv, fetchurl, dpkg, makeWrapper, xz, libX11, gcc, glibc
, libselinux, libXrandr, pango, freetype, fontconfig, glib, gtk
, gdk_pixbuf, cairo, libXi, alsaLib, libXrender, nss, nspr, zlib
, dbus, libpng12, libXfixes, cups, libgcrypt, openal, pulseaudio
@ -97,3 +97,28 @@ stdenv.mkDerivation rec {
license = "unfree";
};
}
*/
{stdenv, fetchurl, dpkg}:
stdenv.mkDerivation {
name = "steam-1.0.0.42";
src = fetchurl {
url = http://repo.steampowered.com/steam/archive/precise/steam-launcher_1.0.0.42_all.deb;
sha256 = "1jyvk0h1z78sdpvl4hs1kdvr6z2kwamf09vjgjx1f6j04kgqrfbw";
};
buildInputs = [ dpkg ];
unpackPhase = "true";
installPhase = ''
mkdir -p $out
dpkg -x $src $out
cp -av $out/usr/* $out
rm -Rf $out/usr
'';
meta = {
description = "A digital distribution platform";
homepage = http://store.steampowered.com/;
license = "unfree";
};
}

View file

@ -266,6 +266,12 @@ let
buildEnv = import ../build-support/buildenv {
inherit (pkgs) runCommand perl;
};
buildFHSChrootEnv = import ../build-support/build-fhs-chrootenv {
inherit stdenv glibc glibcLocales gcc coreutils diffutils findutils;
inherit gnused gnugrep gnutar gzip bzip2 bashInteractive xz shadow gawk;
inherit less buildEnv;
};
dotnetenv = import ../build-support/dotnetenv {
inherit stdenv;
@ -9120,6 +9126,10 @@ let
stardust = callPackage ../games/stardust {};
steam = callPackage_i686 ../games/steam {};
steamChrootEnv = callPackage_i686 ../games/steam/chrootenv.nix {
zenity = gnome2.zenity;
};
stuntrally = callPackage ../games/stuntrally { };