Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swapoff flag #454

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ Options:
build the closure on the remote machine instead of locally and copy-closuring it
* --vm-test
build the system and test the disk configuration inside a VM without installing it to the target.
* --swapoff
turn off swap devices during reboot phase. Enable this if creating a ZFS swap device so it is exported.
```
10 changes: 9 additions & 1 deletion src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ diskoMode="disko"
nixosSystem=""
extraFiles=""
vmTest="n"
swapoff="n"
nixOptions=(
--extra-experimental-features 'nix-command flakes'
"--no-write-lock-file"
Expand Down Expand Up @@ -117,6 +118,8 @@ Options:
* --generate-hardware-config nixos-facter|nixos-generate-config <path>
generate a hardware-configuration.nix file using the specified backend and write it to the specified path.
The backend can be either 'nixos-facter' or 'nixos-generate-config'.
* --swapoff
turn off swap devices during reboot phase. Enable this if creating a ZFS swap device so it is exported.
* --phases
comma separated list of phases to run. Default is: kexec,disko,install,reboot
kexec: kexec into the nixos installer
Expand Down Expand Up @@ -289,6 +292,9 @@ parseArgs() {
--vm-test)
vmTest=y
;;
--swapoff)
swapoff=y
;;
*)
if [[ -z ${sshConnection} ]]; then
sshConnection="$1"
Expand Down Expand Up @@ -619,7 +625,9 @@ 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/
swapoff -a
if [[ ${swapoff} == "y" ]]; then
swapoff -a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't like about this change is that it breaks the export the when people have swap on ZFS.
People shouldn't need to have adding a flag to make nixos-anywhere work.

Copy link
Member

@Mic92 Mic92 Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like this is more sensible:

Suggested change
swapoff -a
# turn all swap devices that are baked by zfs.
swapon --show --noheadings | awk '/^\/dev\/zd/ {print $1}' | while read device; do
swapoff "$device"
done

You would need to have your system not have swap in zfs. However you need to do this anyway because with 1GB you would run into deadlock issues with zfs if you would try to have it in the pool.

fi
zpool export -a || true
fi
nohup sh -c 'sleep 6 && reboot' >/dev/null &
Expand Down
Loading