2013-09-13 23:58:59 +02:00
|
|
|
{stdenv, glibc, glibcLocales, gcc, coreutils, diffutils, findutils, gnused, gnugrep, gnutar, gzip, bzip2,
|
2014-05-22 22:01:00 +02:00
|
|
|
bashInteractive, xz, shadow, gawk, less, buildEnv}:
|
2013-09-13 23:58:59 +02:00
|
|
|
{name, pkgs ? [], profile ? ""}:
|
|
|
|
|
|
|
|
let
|
2014-04-18 13:30:24 +02:00
|
|
|
basePkgs = [
|
|
|
|
glibc glibcLocales gcc coreutils diffutils findutils gnused gnugrep gnutar
|
2014-05-22 22:01:00 +02:00
|
|
|
gzip bzip2 bashInteractive xz shadow gawk less
|
2014-04-18 13:30:24 +02:00
|
|
|
];
|
2013-09-13 23:58:59 +02:00
|
|
|
|
|
|
|
# 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;
|
2014-04-18 13:30:24 +02:00
|
|
|
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
|
2013-09-13 23:58:59 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
}
|