about summary refs log tree commit diff
path: root/nixos/modules/installer/tools
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2019-03-03 21:07:14 +0100
committerMaximilian Bosch <maximilian@mbosch.me>2019-03-08 19:57:02 +0100
commiteaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8 (patch)
tree424bcf3dedcfcd2890e8786acd380ccace320651 /nixos/modules/installer/tools
parent77edcf88dca0de15a2bcf34f8d94f02d1fbd4eab (diff)
downloadnixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar.gz
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar.bz2
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar.lz
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar.xz
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.tar.zst
nixlib-eaf98c7bcf12f5f211126eb82698b8c1e7b7a4d8.zip
nixos/nixos-install: tell the user what to do if setting a root password failed
If setting a root password using the `passwd` call in the
`nixos-install` script fails, it should be explained how set it manually
to ensure that nobody gets accidentally locked out of the system.
Diffstat (limited to 'nixos/modules/installer/tools')
-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 defc46ad2a72..8685cb345e1e 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!"