Skip to content

Commit

Permalink
nixos-anywhere: move unmount into reboot phase
Browse files Browse the repository at this point in the history
This means that users can now access the mounted filesystems by omitting
the `reboot` phase.

You can combine this with `--disko-mode mount` to mount and upgrade an
existing system before running `nixos-enter` to run commands on it.

    $ nixos-anywhere --disko-mode mount --phases kexec,disko,install
  • Loading branch information
Enzime authored and mergify[bot] committed Sep 28, 2024
1 parent 63eae64 commit b6168ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Options:
kexec: kexec into the nixos installer
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
install: install the system
reboot: reboot the machine
reboot: unmount the filesystems, export any ZFS pools and reboot the machine
* --disko-mode disko|mount|format
set the disko mode to format, mount or destroy. Default is disko.
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
Expand Down
18 changes: 8 additions & 10 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Options:
kexec: kexec into the nixos installer
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
install: install the system
reboot: reboot the machine
reboot: unmount the filesystems, export any ZFS pools and reboot the machine
* --disko-mode disko|mount|format
set the disko mode to format, mount or destroy. Default is disko.
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
Expand Down Expand Up @@ -574,10 +574,6 @@ nixosInstall() {
fi

step Installing NixOS
maybeReboot=""
if [[ ${phases[reboot]} == 1 ]]; then
maybeReboot="nohup sh -c 'sleep 6 && reboot' >/dev/null &"
fi
runSsh sh <<SSH
set -eu ${enableDebug}
# when running not in nixos we might miss this directory, but it's needed in the nixos chroot during installation
Expand All @@ -599,12 +595,14 @@ if [ ${copyHostKeys-n} = "y" ]; then
done
fi
nixos-install --no-root-passwd --no-channel-copy --system "$nixosSystem"
if command -v zpool >/dev/null && [ "\$(zpool list)" != "no pools available" ]; then
# we always want to export the zfs pools so people can boot from it without force import
umount -Rv /mnt/
zpool export -a || true
if [[ ${phases[reboot]} == 1 ]]; then
if command -v zpool >/dev/null && [ "\$(zpool list)" != "no pools available" ]; then
# we always want to export the zfs pools so people can boot from it without force import
umount -Rv /mnt/
zpool export -a || true
fi
nohup sh -c 'sleep 6 && reboot' >/dev/null &
fi
${maybeReboot}
SSH

}
Expand Down

0 comments on commit b6168ba

Please sign in to comment.