1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-13 20:30:02 +00:00

uninstaller: init

This commit is contained in:
Daiderd Jordan 2018-01-15 01:12:26 +01:00
parent 86fe053806
commit 6e42f63784
No known key found for this signature in database
GPG key ID: D02435D05B810C96
3 changed files with 97 additions and 0 deletions

View file

@ -76,4 +76,5 @@ in
system = eval.config.system.build.toplevel;
installer = pkgs.callPackage ./pkgs/darwin-installer {};
uninstaller = pkgs.callPackage ./pkgs/darwin-uninstaller {};
}

View file

@ -0,0 +1,45 @@
{ config, lib, pkgs, ... }:
with lib;
{
# We are uninstalling, disable sanity checks.
assertions = mkForce [];
system.activationScripts.checks.text = mkForce "";
# Disable etc, launchd, ...
environment.etc = mkForce {};
launchd.agents = mkForce {};
launchd.daemons = mkForce {};
launchd.user.agents = mkForce {};
system.activationScripts.postUserActivation.text = mkAfter ''
if test -L ~/Applications; then
rm ~/Applications
fi
'';
system.activationScripts.postActivation.text = mkAfter ''
if test -O /nix/store; then
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist || true
sudo cp /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
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
if test -L /etc/static; then
rm /etc/static
fi
'';
}

View file

@ -0,0 +1,51 @@
{ stdenv, nix, pkgs }:
let
nixPath = stdenv.lib.concatStringsSep ":" [
"darwin-config=${toString ./configuration.nix}"
"darwin=${toString ../..}"
"nixpkgs=${toString pkgs.path}"
"$NIX_PATH"
];
in
stdenv.mkDerivation {
name = "darwin-uninstaller";
unpackPhase = ":";
installPhase = ''
mkdir -p $out/bin
echo "$shellHook" > $out/bin/darwin-uninstaller
chmod +x $out/bin/darwin-uninstaller
'';
shellHook = ''
#!/usr/bin/env bash
set -e
action=switch
while [ "$#" -gt 0 ]; do
i="$1"; shift 1
case "$i" in
--help)
echo "darwin-uninstaller: [--check]"
exit
;;
--check)
action=check
;;
esac
done
export nix=${nix}
export NIX_PATH=${nixPath}
system=$($nix/bin/nix-build '<darwin>' -A system)
$system/sw/bin/darwin-rebuild switch
echo >&2
echo >&2 "Done!"
echo >&2
exit
'';
}