#!/bin/sh -eux
-if test $(id -u) != 0
-then sudo "$0" "$@"
-else
- nixos-rebuild switch --flake "${0%/*}"/ "$@"
- nix-env --delete-generations +2 --profile /nix/var/nix/profiles/system
-fi
+cd "${0%/*}"
+chmod -R g-rwx,o-rwx "$PWD/private/root"
+trap 'git reset private/root' EXIT
+git rm -rf --cached --ignore-unmatch private/root # prevent copying to /nix/store
+sudo ln -sfn "$PWD/private/root" /root/private
+# To build offline, use: --option no-net 1 --option substituters ""
+sudo time nixos-rebuild switch --flake . "$@"
+sudo nix-env --delete-generations +9 --profile /nix/var/nix/profiles/system