mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 04:43:09 +03:00
fhs-userenv: refactor and try to chdir to the current directory
runScript now expects a filename instead of a Bash snippet; thus, "exec" should be omitted.
This commit is contained in:
parent
508ef7e629
commit
19c497050e
@ -1,37 +1,21 @@
|
|||||||
{ writeTextFile, stdenv, ruby } : { env, runScript } :
|
{ writeText, writeScriptBin, stdenv, ruby } : { env, runScript } :
|
||||||
|
|
||||||
let
|
let
|
||||||
name = env.pname;
|
name = env.pname;
|
||||||
|
|
||||||
# Sandboxing script
|
# Sandboxing script
|
||||||
chroot-user = writeTextFile {
|
chroot-user = writeScriptBin "chroot-user" ''
|
||||||
name = "chroot-user";
|
#! ${ruby}/bin/ruby
|
||||||
executable = true;
|
${builtins.readFile ./chroot-user.rb}
|
||||||
destination = "/bin/chroot-user";
|
|
||||||
text = ''
|
|
||||||
#! ${ruby}/bin/ruby
|
|
||||||
${builtins.readFile ./chroot-user.rb}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
in stdenv.mkDerivation {
|
|
||||||
name = "${name}-userenv";
|
|
||||||
buildInputs = [ ruby ];
|
|
||||||
preferLocalBuild = true;
|
|
||||||
buildCommand = ''
|
|
||||||
mkdir -p $out/bin
|
|
||||||
cat > $out/bin/${name} <<EOF
|
|
||||||
#! ${stdenv.shell}
|
|
||||||
exec ${chroot-user}/bin/chroot-user ${env} $out/libexec/run "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x $out/bin/${name}
|
|
||||||
|
|
||||||
mkdir -p $out/libexec
|
|
||||||
cat > $out/libexec/run <<EOF
|
|
||||||
#! ${stdenv.shell}
|
|
||||||
source /etc/profile
|
|
||||||
${runScript} "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x $out/libexec/run
|
|
||||||
'';
|
'';
|
||||||
}
|
|
||||||
|
init = writeText "init" ''
|
||||||
|
[ -d "$1" ] && [ -r "$1" ] && cd "$1"
|
||||||
|
shift
|
||||||
|
exec "${runScript}" "$@"
|
||||||
|
'';
|
||||||
|
|
||||||
|
in writeScriptBin name ''
|
||||||
|
#! ${stdenv.shell}
|
||||||
|
exec ${chroot-user}/bin/chroot-user ${env} bash -l ${init} "$(pwd)" "$@"
|
||||||
|
''
|
||||||
|
Loading…
Reference in New Issue
Block a user