git.iko.soy/typeable/nixpkgs
on master help sign in
buildFHSUserEnvBubblewrap: use arrays for constructing argument list

Generally a cleaner way of doing it and prevents issues with spaces in paths Used to fix #97234 but #101967 already didt this with a smaller scope

commit74c4a55e1076ecd93b2e44f44f402b8980cff464 authorAtemu <atemu.main@gmail.com> dateSun 20 Sep 2020, 17:02 (6 years ago) parenta322b32
1 file changed+21−18
pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix+21−18
pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix+21−18
@@ -50,7 +50,7 @@ let
5050 "ssl/certs"
5151 "pki"
5252 ];
53− in concatStringsSep " \\\n "
53+ in concatStringsSep "\n "
5454 (map (file: "--ro-bind-try /etc/${file} /etc/${file}") files);
5555
5656 init = run: writeShellScriptBin "${name}-init" ''
@@ -59,21 +59,21 @@ let
5959 '';
6060
6161 bwrapCmd = { initArgs ? "" }: ''
62− blacklist="/nix /dev /proc /etc"
63− ro_mounts=""
62+ blacklist=(/nix /dev /proc /etc)
63+ ro_mounts=()
6464 for i in ${env}/*; do
6565 path="/''${i##*/}"
6666 if [[ $path == '/etc' ]]; then
6767 continue
6868 fi
69− ro_mounts="$ro_mounts --ro-bind $i $path"
70− blacklist="$blacklist $path"
69+ ro_mounts+=(--ro-bind "$i" "$path")
70+ blacklist+=("$path")
7171 done
7272
7373 if [[ -d ${env}/etc ]]; then
7474 for i in ${env}/etc/*; do
7575 path="/''${i##*/}"
76− ro_mounts="$ro_mounts --ro-bind $i /etc$path"
76+ ro_mounts+=(--ro-bind "$i" "/etc$path")
7777 done
7878 fi
7979
@@ -81,24 +81,27 @@ let
8181 # loop through all directories in the root
8282 for dir in /*; do
8383 # if it is a directory and it is not in the blacklist
84− if [[ -d "$dir" ]] && grep -v "$dir" <<< "$blacklist" >/dev/null; then
84+ if [[ -d "$dir" ]] && [[ ! "''${blacklist[@]}" =~ "$dir" ]]; then
8585 # add it to the mount list
8686 auto_mounts+=(--bind "$dir" "$dir")
8787 fi
8888 done
8989
90− exec ${bubblewrap}/bin/bwrap \
91− --dev-bind /dev /dev \
92− --proc /proc \
93− --chdir "$(pwd)" \
94− --unshare-all \
95− --share-net \
96− --die-with-parent \
97− --ro-bind /nix /nix \
98− ${etcBindFlags} \
99− $ro_mounts \
100− "''${auto_mounts[@]}" \
90+ cmd=(
91+ ${bubblewrap}/bin/bwrap
92+ --dev-bind /dev /dev
93+ --proc /proc
94+ --chdir "$(pwd)"
95+ --unshare-all
96+ --share-net
97+ --die-with-parent
98+ --ro-bind /nix /nix
99+ ${etcBindFlags}
100+ "''${ro_mounts[@]}"
101+ "''${auto_mounts[@]}"
101102 ${init runScript}/bin/${name}-init ${initArgs}
103+ )
104+ exec "''${cmd[@]}"
102105 '';
103106
104107 bin = writeShellScriptBin name (bwrapCmd { initArgs = ''"$@"''; });