From 5b82b8d0946fb5686c8fa77727650056001222ac Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 4 Nov 2020 16:11:05 +0900 Subject: [PATCH] dockerTools: fix absent /proc during runAsRoot The chroot environment under mnt had /dev and /sys via bind mounts, but nothing setting up /proc. The `--mount-proc` argument to unshare defaults to /proc, which is outside of the chroot envirnoment. --- pkgs/build-support/docker/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 35382662cf815e..d197fc5ed405aa 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -410,7 +410,11 @@ rec { # details on what's going on here; basically this command # means that the runAsRootScript will be executed in a nearly # completely isolated environment. - unshare -imnpuf --mount-proc chroot mnt ${runAsRootScript} + # + # Ideally we would use --mount-proc=mnt/proc or similar, but this + # doesn't work. The workaround is to setup proc after unshare. + # See: https://github.com/karelzak/util-linux/issues/648 + unshare -imnpuf --mount-proc sh -c 'mount --rbind /proc mnt/proc && chroot mnt ${runAsRootScript}' # Unmount directories and remove them. umount -R mnt/dev mnt/sys mnt${storeDir}