2015-02-05 15:14:28 +00:00
|
|
|
{ writeTextFile, stdenv, ruby } : { env, runScript } :
|
|
|
|
|
|
|
|
let
|
|
|
|
name = env.pname;
|
|
|
|
|
|
|
|
# Sandboxing script
|
|
|
|
chroot-user = writeTextFile {
|
|
|
|
name = "chroot-user";
|
|
|
|
executable = true;
|
|
|
|
destination = "/bin/chroot-user";
|
|
|
|
text = ''
|
|
|
|
#! ${ruby}/bin/ruby
|
|
|
|
${builtins.readFile ./chroot-user.rb}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
2015-02-05 17:39:01 +00:00
|
|
|
name = "${name}-userenv";
|
2015-02-05 15:14:28 +00:00
|
|
|
buildInputs = [ ruby ];
|
2015-02-05 17:39:01 +00:00
|
|
|
preferLocalBuild = true;
|
2015-02-05 15:14:28 +00:00
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cat > $out/bin/${name} <<EOF
|
|
|
|
#! ${stdenv.shell}
|
2015-03-10 06:26:08 +00:00
|
|
|
exec ${chroot-user}/bin/chroot-user ${env} $out/libexec/run "\$@"
|
2015-02-05 15:14:28 +00:00
|
|
|
EOF
|
|
|
|
chmod +x $out/bin/${name}
|
|
|
|
|
|
|
|
mkdir -p $out/libexec
|
|
|
|
cat > $out/libexec/run <<EOF
|
|
|
|
#! ${stdenv.shell}
|
|
|
|
source /etc/profile
|
2015-03-10 06:26:08 +00:00
|
|
|
${runScript} "\$@"
|
2015-02-05 15:14:28 +00:00
|
|
|
EOF
|
|
|
|
chmod +x $out/libexec/run
|
|
|
|
'';
|
|
|
|
}
|