From 687e2195d8076b0cef3e29c719fb5ab35975c160 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 20 Feb 2020 18:19:05 -0500 Subject: [PATCH] runInLinuxVM: Ensure tools requiring /etc/passwd work This includes, but is not limited to: * whoami * nix >= 2.3.1 See * https://github.com/NixOS/nixpkgs/issues/71157 * https://github.com/NixOS/nixops/issues/1216 * https://github.com/nix-community/nixops-libvirtd/issues/5 --- pkgs/build-support/vm/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index a7050f52e521..488c7f2ce2c7 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -126,6 +126,10 @@ rec { mkdir -p /fs/etc ln -sf /proc/mounts /fs/etc/mtab echo "127.0.0.1 localhost" > /fs/etc/hosts + # Ensures tools requiring /etc/passwd will work (e.g. nix) + if [ ! -e /fs/etc/passwd ]; then + echo "root:x:0:0:System administrator:/root:/bin/sh" > /fs/etc/passwd + fi echo "starting stage 2 ($command)" exec switch_root /fs $command $out