dockerTools: fixes extraCommands for mkRootLayer.

The extraCommands was, previously, simply put in the body of the script
using nix expansion `${extraCommands}` (which looks exactly like bash
expansion!).

This causes issues like in #34779 where scripts will eventually create
invalid bash.

The solution is to use a script like `run-as-root`.

 * * *

Fixes #34779
This commit is contained in:
Samuel Dionne-Riel 2018-05-22 19:53:28 -04:00
parent 090b7cc8f1
commit 60737bd319

View file

@ -360,7 +360,9 @@ rec {
extraCommands ? ""
}:
# Generate an executable script from the `runAsRoot` text.
let runAsRootScript = shellScript "run-as-root.sh" runAsRoot;
let
runAsRootScript = shellScript "run-as-root.sh" runAsRoot;
extraCommandsScript = shellScript "extra-commands.sh" extraCommands;
in runWithOverlay {
name = "docker-layer-${name}";
@ -398,7 +400,7 @@ rec {
'';
postUmount = ''
(cd layer; eval "${extraCommands}")
(cd layer; ${extraCommandsScript})
echo "Packing layer..."
mkdir $out