#!/bin/sh -eux
-sudo nixos-rebuild switch --flake "${0%/*}"/ "$@"
-sudo nix-env --delete-generations +2 --profile /nix/var/nix/profiles/system
+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