Remove hacks from darwin nix purge script (#18656)
## Summary In this commit we : - instead of `cd` to `/Library/LaunchDaemons` and then attempting to `launchctl unload` the nixos plist files we just pass the full path to unload as seen in `nix` documentation here : https://nixos.org/manual/nix/stable/installation/uninstall.html#:~:text=Stop%20and%20remove%20the%20Nix%20daemon%20services%3A - move killing a process by prompting for confirmation to a new shell script as per feedback from previous PR : https://github.com/status-im/status-mobile/pull/18192#discussion_r1439495310 - fix few small typos ## Platforms - macOS
This commit is contained in:
parent
ab509da60e
commit
f57a26b5f5
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
# script to prompt user for terminating a process
|
||||
|
||||
pid="${1}"
|
||||
|
||||
read -p "Do you want to terminate this process? (y/n): " choice
|
||||
if [[ "${choice}" == "y" ]]; then
|
||||
sudo kill "${pid}"
|
||||
echo "Process ${pid} terminated."
|
||||
else
|
||||
echo "Process not terminated. Please close it manually and retry."
|
||||
exit 1
|
||||
fi
|
|
@ -22,12 +22,10 @@ nix_purge_linux_multi_user_users() {
|
|||
}
|
||||
|
||||
nix_purge_darwin_multi_user_service() {
|
||||
cd /Library/LaunchDaemons
|
||||
NIX_SERVICES=(org.nixos.darwin-store.plist org.nixos.nix-daemon.plist)
|
||||
for NIX_SERVICE in "${NIX_SERVICES[@]}"; do
|
||||
sudo launchctl unload "${NIX_SERVICE}" || true
|
||||
sudo launchctl remove "${NIX_SERVICE}" || true
|
||||
done
|
||||
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
||||
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
||||
sudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plist
|
||||
sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist
|
||||
}
|
||||
|
||||
nix_purge_darwin_multi_user_users() {
|
||||
|
@ -48,18 +46,10 @@ nix_purge_darwin_multi_user_volumes() {
|
|||
|
||||
# Identify the process using the volume
|
||||
local pid=$(lsof +D /nix | awk 'NR==2{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
if [[ -n "$pid" ]]; then
|
||||
echo "The volume /nix is in use by process ID $pid."
|
||||
"${GIT_ROOT}/nix/scripts/kill_proc_prompt.sh" "${pid}" || return 1
|
||||
|
||||
# Ask the user whether to terminate the process
|
||||
read -p "Do you want to terminate this process? (y/n): " choice
|
||||
if [[ $choice == "y" ]]; then
|
||||
sudo kill $pid
|
||||
echo "Process $pid terminated."
|
||||
else
|
||||
echo "Process not terminated. Please close it manually and retry."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "No process found using /nix. Manual intervention required."
|
||||
return 1
|
||||
|
@ -71,9 +61,9 @@ nix_purge_darwin_multi_user_volumes() {
|
|||
|
||||
nix_purge_multi_user() {
|
||||
if [[ $(uname -s) == "Darwin" ]]; then
|
||||
nix_purge_darwin_multi_user_service || true
|
||||
nix_purge_darwin_multi_user_users || true
|
||||
nix_purge_darwin_multi_user_volumes || true
|
||||
nix_purge_darwin_multi_user_service
|
||||
nix_purge_darwin_multi_user_users
|
||||
nix_purge_darwin_multi_user_volumes
|
||||
else
|
||||
nix_purge_linux_multi_user_service
|
||||
nix_purge_linux_multi_user_users
|
||||
|
@ -117,7 +107,7 @@ if (return 0 2>/dev/null); then
|
|||
return
|
||||
fi
|
||||
|
||||
# Confirm user decission, unless --force is used.
|
||||
# Confirm user decision, unless --force is used.
|
||||
if [[ "${1}" != "--force" ]]; then
|
||||
echo -e "${YLW}Are you sure you want to purge Nix?${RST}" >&2
|
||||
read -p "[y/n]: " -n 1 -r
|
||||
|
@ -129,7 +119,7 @@ if [[ "${1}" != "--force" ]]; then
|
|||
fi
|
||||
|
||||
NIX_INSTALL_TYPE=$(nix_install_type)
|
||||
# Purging /nix on NixOS would be disasterous.
|
||||
# Purging /nix on NixOS would be disastrous.
|
||||
if [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
|
||||
echo -e "${RED}You should not purge Nix files on NixOS!${RST}" >&2
|
||||
exit
|
||||
|
|
Loading…
Reference in New Issue