about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorSilvan Mosberger <infinisil@icloud.com>2019-03-08 21:05:48 +0100
committerGitHub <noreply@github.com>2019-03-08 21:05:48 +0100
commita95182882fb1d4bc203c07b655f57fe0a4b2b8f4 (patch)
tree09751ff5ddbdad18a5e0d93381a56e119afbf7b5 /nixos
parent2e92520e21ad81513997151ee31facdbaf0b7f8e (diff)
parenteaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8 (diff)
Merge pull request #56790 from Ma27/improve-error-handling-for-nixos-install
nixos/nixos-install: tell the user what to do if setting a root password failed
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-install.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh
index defc46ad2a723..8685cb345e1e1 100644
--- a/nixos/modules/installer/tools/nixos-install.sh
+++ b/nixos/modules/installer/tools/nixos-install.sh
@@ -138,7 +138,18 @@ fi
 # Ask the user to set a root password, but only if the passwd command
 # exists (i.e. when mutable user accounts are enabled).
 if [[ -z $noRootPasswd ]] && [ -t 0 ]; then
-    nixos-enter --root "$mountPoint" -c '[[ -e /nix/var/nix/profiles/system/sw/bin/passwd ]] && echo "setting root password..." && /nix/var/nix/profiles/system/sw/bin/passwd'
+    if nixos-enter --root "$mountPoint" -c 'test -e /nix/var/nix/profiles/system/sw/bin/passwd'; then
+        set +e
+        nixos-enter --root "$mountPoint" -c 'echo "setting root password..." && /nix/var/nix/profiles/system/sw/bin/passwd'
+        exit_code=$?
+        set -e
+
+        if [[ $exit_code != 0 ]]; then
+            echo "Setting a root password failed with the above printed error."
+            echo "You can set the root password manually by executing \`nixos-enter --root ${mountPoint@Q}\` and then running \`passwd\` in the shell of the new system."
+            exit $exit_code
+        fi
+    fi
 fi
 
 echo "installation finished!"