2024-06-24 21:28:36 +02:00
|
|
|
#!/usr/bin/env bash
|
2017-07-12 16:46:29 +02:00
|
|
|
|
2017-07-12 23:10:14 +02:00
|
|
|
set -eux
|
|
|
|
|
2017-07-12 16:46:29 +02:00
|
|
|
cleanup() {
|
|
|
|
PLIST="/Library/LaunchDaemons/org.nixos.nix-daemon.plist"
|
2021-12-09 16:26:46 +01:00
|
|
|
if sudo launchctl list | grepQuiet nix-daemon; then
|
2017-07-12 16:46:29 +02:00
|
|
|
sudo launchctl unload "$PLIST"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$PLIST" ]; then
|
|
|
|
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
|
|
fi
|
|
|
|
|
|
|
|
profiles=(/etc/profile /etc/bashrc /etc/zshrc)
|
|
|
|
for profile in "${profiles[@]}"; do
|
|
|
|
if [ -f "${profile}.backup-before-nix" ]; then
|
|
|
|
sudo mv "${profile}.backup-before-nix" "${profile}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-07-13 02:29:58 +02:00
|
|
|
for file in ~/.bash_profile ~/.bash_login ~/.profile ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin; do
|
2017-07-13 02:31:33 +02:00
|
|
|
if [ -e "$file" ]; then
|
|
|
|
cat "$file" | grep -v nix-profile > "$file.next"
|
|
|
|
mv "$file.next" "$file"
|
|
|
|
fi
|
2017-07-13 02:29:58 +02:00
|
|
|
done
|
|
|
|
|
2017-07-12 16:46:29 +02:00
|
|
|
for i in $(seq 1 $(sysctl -n hw.ncpu)); do
|
|
|
|
sudo /usr/bin/dscl . -delete "/Users/nixbld$i" || true
|
|
|
|
done
|
|
|
|
sudo /usr/bin/dscl . -delete "/Groups/nixbld" || true
|
|
|
|
|
|
|
|
sudo rm -rf /etc/nix \
|
|
|
|
/nix \
|
|
|
|
/var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels \
|
2019-07-25 15:43:24 +02:00
|
|
|
"$HOME/.nix-profile" "$HOME/.nix-defexpr" "$HOME/.nix-channels"
|
2017-07-12 16:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
verify() {
|
2017-07-13 02:43:57 +02:00
|
|
|
set +e
|
2017-07-12 16:46:29 +02:00
|
|
|
output=$(echo "nix-shell -p bash --run 'echo toow | rev'" | bash -l)
|
2017-07-13 02:43:57 +02:00
|
|
|
set -e
|
|
|
|
|
2017-07-12 16:46:29 +02:00
|
|
|
test "$output" = "woot"
|
|
|
|
}
|
|
|
|
|
|
|
|
scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
|
|
|
|
function finish {
|
|
|
|
rm -rf "$scratch"
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
# First setup Nix
|
|
|
|
cleanup
|
2020-09-12 22:08:40 +02:00
|
|
|
curl -L -o install https://nixos.org/nix/install
|
2017-07-13 23:22:54 +02:00
|
|
|
yes | bash ./install
|
2017-07-12 16:46:29 +02:00
|
|
|
verify
|
|
|
|
|
|
|
|
|
|
|
|
(
|
2017-07-13 02:43:57 +02:00
|
|
|
set +e
|
2017-07-12 23:10:14 +02:00
|
|
|
(
|
|
|
|
echo "cd $(pwd)"
|
|
|
|
echo nix-build ./release.nix -A binaryTarball.x86_64-darwin
|
|
|
|
) | bash -l
|
2017-07-13 02:43:57 +02:00
|
|
|
set -e
|
2017-07-12 16:46:29 +02:00
|
|
|
cp ./result/nix-*.tar.bz2 $scratch/nix.tar.bz2
|
|
|
|
)
|
|
|
|
|
|
|
|
(
|
|
|
|
cd $scratch
|
|
|
|
tar -xf ./nix.tar.bz2
|
|
|
|
|
|
|
|
cd nix-*
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
yes | ./install
|
|
|
|
verify
|
|
|
|
cleanup
|
|
|
|
|
2017-07-13 23:22:54 +02:00
|
|
|
echo -n "" | ./install
|
2017-07-12 16:46:29 +02:00
|
|
|
verify
|
2017-07-14 00:01:22 +02:00
|
|
|
cleanup
|
2017-07-12 16:46:29 +02:00
|
|
|
|
2017-07-14 00:01:22 +02:00
|
|
|
sudo mkdir -p /nix/store
|
|
|
|
sudo touch /nix/store/.silly-hint
|
2017-07-14 12:28:24 +02:00
|
|
|
echo -n "" | ALLOW_PREEXISTING_INSTALLATION=true ./install
|
2017-07-14 00:01:22 +02:00
|
|
|
verify
|
|
|
|
test -e /nix/store/.silly-hint
|
2017-07-14 01:03:35 +02:00
|
|
|
|
2017-07-12 16:46:29 +02:00
|
|
|
cleanup
|
|
|
|
)
|