2024-11-05 02:48:25 +11:00
|
|
|
{ lib, path, stdenv, writeShellApplication }:
|
2018-01-15 01:12:26 +01:00
|
|
|
|
|
|
|
let
|
2023-11-10 12:53:56 -05:00
|
|
|
uninstallSystem = import ../../eval-config.nix {
|
|
|
|
inherit lib;
|
|
|
|
modules = [
|
|
|
|
./configuration.nix
|
|
|
|
{
|
2024-11-05 02:48:25 +11:00
|
|
|
nixpkgs.source = path;
|
|
|
|
nixpkgs.hostPlatform = stdenv.hostPlatform.system;
|
2023-11-10 12:53:56 -05:00
|
|
|
system.includeUninstaller = false;
|
|
|
|
}
|
|
|
|
];
|
2020-08-14 23:25:26 +02:00
|
|
|
};
|
2024-11-05 02:48:25 +11:00
|
|
|
in writeShellApplication {
|
2018-01-15 01:12:26 +01:00
|
|
|
name = "darwin-uninstaller";
|
2024-11-05 02:48:25 +11:00
|
|
|
text = ''
|
2018-01-15 01:12:26 +01:00
|
|
|
while [ "$#" -gt 0 ]; do
|
2024-11-05 02:48:25 +11:00
|
|
|
i="$1"; shift 1
|
|
|
|
case "$i" in
|
|
|
|
--help)
|
|
|
|
echo "darwin-uninstaller: [--help]"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
2018-01-15 01:12:26 +01:00
|
|
|
done
|
|
|
|
|
2018-01-15 22:31:50 +01:00
|
|
|
echo >&2
|
|
|
|
echo >&2 "Uninstalling nix-darwin, this will:"
|
|
|
|
echo >&2
|
2023-07-11 18:52:49 +10:00
|
|
|
echo >&2 " - remove /Applications/Nix Apps symlink"
|
|
|
|
echo >&2 " - cleanup static /etc files"
|
|
|
|
echo >&2 " - disable and remove all launchd services managed by nix-darwin"
|
|
|
|
echo >&2 " - restore daemon service from nix installer (only when this is a multi-user install)"
|
2018-01-15 22:31:50 +01:00
|
|
|
echo >&2
|
|
|
|
|
2024-11-05 02:48:25 +11:00
|
|
|
if [[ -t 0 ]]; then
|
|
|
|
read -r -p "Proceed? [y/n] " i
|
|
|
|
case "$i" in
|
|
|
|
y|Y)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
2018-01-15 22:31:50 +01:00
|
|
|
fi
|
|
|
|
|
2023-11-10 12:53:56 -05:00
|
|
|
${uninstallSystem.system}/sw/bin/darwin-rebuild activate
|
2018-01-15 01:12:26 +01:00
|
|
|
|
2024-11-05 00:54:34 +11:00
|
|
|
if [[ -L /run/current-system ]]; then
|
2018-01-17 22:16:48 +01:00
|
|
|
sudo rm /run/current-system
|
2018-01-15 22:31:50 +01:00
|
|
|
fi
|
|
|
|
|
2024-11-05 00:54:34 +11:00
|
|
|
if [[ -L /run ]]; then
|
|
|
|
if [[ -e /etc/synthetic.conf ]]; then
|
|
|
|
sudo sed -i -E '/^run[[:space:]]/d' /etc/synthetic.conf
|
|
|
|
sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B &>/dev/null || true
|
|
|
|
sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t &>/dev/null || true
|
|
|
|
echo >&2 "NOTE: the /run symlink will be removed on reboot"
|
|
|
|
else
|
|
|
|
sudo rm /run
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-01-15 22:31:50 +01:00
|
|
|
echo >&2
|
|
|
|
echo >&2 "NOTE: The /nix/var/nix/profiles/system* profiles still exist and won't be garbage collected."
|
2018-01-15 01:12:26 +01:00
|
|
|
echo >&2
|
|
|
|
echo >&2 "Done!"
|
|
|
|
echo >&2
|
|
|
|
'';
|
2018-01-17 21:36:15 +01:00
|
|
|
|
2024-11-05 02:48:25 +11:00
|
|
|
derivationArgs.passthru.tests.uninstaller = writeShellApplication {
|
|
|
|
name = "post-uninstall-test";
|
|
|
|
text = ''
|
|
|
|
echo >&2 "running uninstaller tests..."
|
|
|
|
echo >&2
|
2018-01-17 21:36:15 +01:00
|
|
|
|
2024-11-05 02:48:25 +11:00
|
|
|
echo >&2 "checking darwin channel"
|
|
|
|
test -e ~/.nix-defexpr/channels/darwin && exit 1
|
|
|
|
echo >&2 "checking /etc"
|
|
|
|
test -e /etc/static && exit 1
|
|
|
|
echo >&2 "checking /run/current-system"
|
|
|
|
test -e /run/current-system && exit 1
|
2024-11-07 14:19:19 +11:00
|
|
|
if [[ $(stat -f '%Su' /nix/store) == "root" ]]; then
|
|
|
|
echo >&2 "checking nix-daemon service"
|
|
|
|
launchctl print system/org.nixos.nix-daemon
|
|
|
|
pgrep -l nix-daemon
|
|
|
|
test -e /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
|
|
[[ "$(shasum -a 256 /Library/LaunchDaemons/org.nixos.nix-daemon.plist | awk '{print $1}')" == "$(shasum -a 256 /Library/LaunchDaemons/org.nixos.nix-daemon.plist | awk '{print $1}')" ]]
|
|
|
|
echo >&2 ok
|
|
|
|
fi
|
2018-01-17 21:36:15 +01:00
|
|
|
'';
|
|
|
|
};
|
2018-01-15 01:12:26 +01:00
|
|
|
}
|