diff options
author | Sander van der Burg <svanderburg@gmail.com> | 2013-09-13 23:58:59 +0200 |
---|---|---|
committer | Sander van der Burg <svanderburg@gmail.com> | 2013-09-13 23:58:59 +0200 |
commit | 28d8e938714a77af473a549e647e07573cc4b959 (patch) | |
tree | f2d870266655ef44f157fb25b7539eeaab50c43b /pkgs/build-support | |
parent | e67a2479e13e747bacbe43d369175386079095a6 (diff) | |
download | nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar.gz nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar.bz2 nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar.lz nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar.xz nixlib-28d8e938714a77af473a549e647e07573cc4b959.tar.zst nixlib-28d8e938714a77af473a549e647e07573cc4b959.zip |
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
Diffstat (limited to 'pkgs/build-support')
6 files changed, 188 insertions, 0 deletions
diff --git a/pkgs/build-support/build-fhs-chrootenv/default.nix b/pkgs/build-support/build-fhs-chrootenv/default.nix new file mode 100644 index 000000000000..8756c4835b29 --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/default.nix @@ -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 + ''; +} diff --git a/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in b/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in new file mode 100644 index 000000000000..30b51cb5068f --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in @@ -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 diff --git a/pkgs/build-support/build-fhs-chrootenv/init.sh.in b/pkgs/build-support/build-fhs-chrootenv/init.sh.in new file mode 100644 index 000000000000..2dfa95219c85 --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/init.sh.in @@ -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 diff --git a/pkgs/build-support/build-fhs-chrootenv/load.sh.in b/pkgs/build-support/build-fhs-chrootenv/load.sh.in new file mode 100644 index 000000000000..8d3f464186b7 --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/load.sh.in @@ -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 diff --git a/pkgs/build-support/build-fhs-chrootenv/mount.sh.in b/pkgs/build-support/build-fhs-chrootenv/mount.sh.in new file mode 100644 index 000000000000..68459cca2560 --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/mount.sh.in @@ -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 diff --git a/pkgs/build-support/build-fhs-chrootenv/umount.sh.in b/pkgs/build-support/build-fhs-chrootenv/umount.sh.in new file mode 100644 index 000000000000..29d631fbd90b --- /dev/null +++ b/pkgs/build-support/build-fhs-chrootenv/umount.sh.in @@ -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} |