summaryrefslogtreecommitdiff
path: root/pkgs/darwin-uninstaller
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/darwin-uninstaller')
-rw-r--r--pkgs/darwin-uninstaller/configuration.nix45
-rw-r--r--pkgs/darwin-uninstaller/default.nix115
2 files changed, 80 insertions, 80 deletions
diff --git a/pkgs/darwin-uninstaller/configuration.nix b/pkgs/darwin-uninstaller/configuration.nix
index 6487774..295477a 100644
--- a/pkgs/darwin-uninstaller/configuration.nix
+++ b/pkgs/darwin-uninstaller/configuration.nix
@@ -1,4 +1,4 @@
-{ lib, ... }:
+{ lib, pkgs, ... }:
with lib;
@@ -7,46 +7,49 @@ with lib;
assertions = mkForce [];
system.activationScripts.checks.text = mkForce "";
- # Disable etc, launchd, ...
environment.etc = mkForce {};
launchd.agents = mkForce {};
launchd.daemons = mkForce {};
launchd.user.agents = mkForce {};
+ # Don't try to reload `nix-daemon`
+ nix.useDaemon = mkForce false;
+
system.activationScripts.postUserActivation.text = mkAfter ''
- if test -L ~/.nix-defexpr/channels/darwin; then
+ if [[ -L ~/.nix-defexpr/channels/darwin ]]; then
nix-channel --remove darwin || true
fi
'';
system.activationScripts.postActivation.text = mkAfter ''
- if test -L /Applications/Nix\ Apps; then
+ if [[ -L /Applications/Nix\ Apps ]]; then
rm /Applications/Nix\ Apps
fi
- if test -L /etc/static; then
+ if [[ -L /etc/static ]]; then
rm /etc/static
fi
- if test -O /nix/store; then
- if ! test -e /Library/LaunchDaemons/org.nixos.nix-daemon.plist; then
- sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist || true
- sudo launchctl remove org.nixos.nix-daemon 2> /dev/null || true
+ # If the Nix Store is owned by root then we're on a multi-user system
+ if [[ -O /nix/store ]]; then
+ if [[ -e /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist ]]; then
sudo cp /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl load -w /Library/LaunchDaemons/org.nixos.nix-daemon.plist
fi
-
- if ! grep -q etc/profile.d/nix-daemon.sh /etc/bashrc; then
- echo >&2 "Found no nix-daemon.sh reference in /etc/bashrc"
- echo >&2 "add this snippet back to /etc/bashrc:"
- echo >&2
- echo >&2 " # Nix"
- echo >&2 " if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then"
- echo >&2 " . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'"
- echo >&2 " fi"
- echo >&2 " # End Nix"
- echo >&2
- fi
fi
+
+ # grep will return 1 when no lines matched which makes this line fail with `set -eo pipefail`
+ dscl . -list /Users UserShell | { grep "\s/run/" || true; } | awk '{print $1}' | while read -r user; do
+ shell=$(dscl . -read /Users/"$user" UserShell)
+ if [[ "$shell" != */bin/zsh ]]; then
+ echo >&2 "warning: changing $user's shell from $shell to /bin/zsh"
+ fi
+
+ dscl . -create /Users/"$user" UserShell /bin/zsh
+ done
+
+ while IFS= read -r -d "" file; do
+ mv "$file" "''${file%.*}"
+ done < <(find /etc -name '*.before-nix-darwin' -follow -print0)
'';
}
diff --git a/pkgs/darwin-uninstaller/default.nix b/pkgs/darwin-uninstaller/default.nix
index 3eb2c24..da58682 100644
--- a/pkgs/darwin-uninstaller/default.nix
+++ b/pkgs/darwin-uninstaller/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, pkgs }:
+{ lib, path, stdenv, writeShellApplication }:
let
uninstallSystem = import ../../eval-config.nix {
@@ -6,39 +6,23 @@ let
modules = [
./configuration.nix
{
- nixpkgs.source = pkgs.path;
- nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform.system;
+ nixpkgs.source = path;
+ nixpkgs.hostPlatform = stdenv.hostPlatform.system;
system.includeUninstaller = false;
}
];
};
-in
-
-stdenv.mkDerivation {
+in writeShellApplication {
name = "darwin-uninstaller";
- preferLocalBuild = true;
-
- unpackPhase = ":";
-
- installPhase = ''
- mkdir -p $out/bin
- echo "$shellHook" > $out/bin/darwin-uninstaller
- chmod +x $out/bin/darwin-uninstaller
- '';
-
- shellHook = ''
- #!${stdenv.shell}
- set -e
-
- action=switch
+ text = ''
while [ "$#" -gt 0 ]; do
- i="$1"; shift 1
- case "$i" in
- --help)
- echo "darwin-uninstaller: [--help]"
- exit
- ;;
- esac
+ i="$1"; shift 1
+ case "$i" in
+ --help)
+ echo "darwin-uninstaller: [--help]"
+ exit
+ ;;
+ esac
done
echo >&2
@@ -47,54 +31,67 @@ stdenv.mkDerivation {
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)"
+ if [[ $(stat -f '%Su' /nix/store) == "root" ]]; then
+ echo >&2 " - restore nix-daemon service from nix installer as this is a multi-user install"
+ fi
echo >&2
- if test -t 0; then
- read -p "Proceed? [y/n] " i
- case "$i" in
- y|Y)
- ;;
- *)
- exit 3
- ;;
- esac
+ if [[ -t 0 ]]; then
+ read -r -p "Proceed? [y/n] " i
+ case "$i" in
+ y|Y)
+ ;;
+ *)
+ exit 3
+ ;;
+ esac
fi
${uninstallSystem.system}/sw/bin/darwin-rebuild activate
- if test -L /run/current-system; then
+ if [[ -L /run/current-system ]]; then
sudo rm /run/current-system
fi
+ 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
+
echo >&2
echo >&2 "NOTE: The /nix/var/nix/profiles/system* profiles still exist and won't be garbage collected."
echo >&2
echo >&2 "Done!"
echo >&2
- exit
'';
- passthru.check = stdenv.mkDerivation {
- name = "run-darwin-test";
- shellHook = ''
- set -e
- echo >&2 "running uninstaller tests..."
- echo >&2
+ derivationArgs.passthru.tests.uninstaller = writeShellApplication {
+ name = "post-uninstall-test";
+ text = ''
+ echo >&2 "running uninstaller tests..."
+ echo >&2
- echo >&2 "checking darwin channel"
- ! test -e ~/.nix-defexpr/channels/darwin
- echo >&2 "checking /etc"
- ! test -e /etc/static
- echo >&2 "checking /run/current-system"
- ! test -e /run/current-system
- echo >&2 "checking nix-daemon service (assuming a multi-user install)"
- sudo launchctl list | grep org.nixos.nix-daemon || echo "FIXME? sudo launchctl list | grep org.nixos.nix-daemon"
- pgrep -l nix-daemon || echo "FIXME? pgrep -l nix-daemon"
- readlink /Library/LaunchDaemons/org.nixos.nix-daemon.plist || echo "FIXME? readlink /Library/LaunchDaemons/org.nixos.nix-daemon.plist"
- grep /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt /Library/LaunchDaemons/org.nixos.nix-daemon.plist || echo "FIXME? grep /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt /Library/LaunchDaemons/org.nixos.nix-daemon.plist"
- echo >&2 ok
- exit
+ 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}')" ]]
+ nix-store --store daemon -q --hash ${stdenv.shell}
+ fi
+ echo >&2 ok
'';
};
}