carotte: fix paths to profiles
[julm/julm-nix.git] / install
diff --git a/install b/install
index 5e2da17dc6cc7ce7795deeabf9d3dfea76b8a1cb..fa3c41c2a276b6c6cc09cbbd0cdb7a28888d44c9 100755 (executable)
--- a/install
+++ b/install
@@ -1,2 +1,12 @@
 #!/bin/sh -eux
-sudo nixos-rebuild switch --flake . "$@"
+if test "$(id -u)" != 0
+then sudo "$0" "$@"
+else
+  cd "${0%/*}"
+  chmod -R g-rwx,o-rwx "$PWD/private/root"
+  ln -sfn "$PWD/private/root" /root/private
+  trap 'git reset private/root' EXIT
+  git rm -rf --cached --ignore-unmatch private/root # prevent copying to /nix/store
+  nixos-rebuild switch --flake . "$@"
+  nix-env --delete-generations +9 --profile /nix/var/nix/profiles/system
+fi