1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 16:57:08 +00:00
nix-darwin/pkgs/darwin-uninstaller/default.nix

95 lines
2.8 KiB
Nix
Raw Normal View History

{ lib, path, stdenv, writeShellApplication }:
2018-01-15 01:12:26 +01:00
let
uninstallSystem = import ../../eval-config.nix {
inherit lib;
modules = [
./configuration.nix
{
nixpkgs.source = path;
nixpkgs.hostPlatform = stdenv.hostPlatform.system;
system.includeUninstaller = false;
}
];
};
in writeShellApplication {
2018-01-15 01:12:26 +01:00
name = "darwin-uninstaller";
text = ''
2018-01-15 01:12:26 +01:00
while [ "$#" -gt 0 ]; do
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
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
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
${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
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
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
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
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
}