From 09284ab00b2bf86b0d33bae8cf8b1a999bb512d9 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 10 Nov 2023 12:53:56 -0500 Subject: [PATCH] Install darwin-uninstall by default, which includes the 'empty' config it switches to Co-Authored-By: Michael Hoang --- default.nix | 4 ++-- flake.nix | 2 +- modules/nix/nix-darwin.nix | 16 +++++++++---- pkgs/darwin-uninstaller/configuration.nix | 2 +- pkgs/darwin-uninstaller/default.nix | 28 ++++++++++------------- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/default.nix b/default.nix index 7c7e06b2..c93b4783 100644 --- a/default.nix +++ b/default.nix @@ -16,7 +16,7 @@ let }; }; - # The source code of this repo needed by the [un]installers. + # The source code of this repo needed by the installer. nix-darwin = lib.cleanSource ( lib.cleanSourceWith { # We explicitly specify a name here otherwise `cleanSource` will use the @@ -30,5 +30,5 @@ in eval // { installer = pkgs.callPackage ./pkgs/darwin-installer { inherit nix-darwin; }; - uninstaller = pkgs.callPackage ./pkgs/darwin-uninstaller { inherit nix-darwin; }; + uninstaller = pkgs.callPackage ./pkgs/darwin-uninstaller { }; } diff --git a/flake.nix b/flake.nix index d09f4d6c..e25fe6a6 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ overlays.default = final: prev: { inherit (prev.callPackage ./pkgs/nix-tools { }) darwin-rebuild darwin-option darwin-version; - darwin-uninstaller = prev.callPackage ./pkgs/darwin-uninstaller { nix-darwin = self; }; + darwin-uninstaller = prev.callPackage ./pkgs/darwin-uninstaller { }; }; darwinModules.hydra = ./modules/examples/hydra.nix; diff --git a/modules/nix/nix-darwin.nix b/modules/nix/nix-darwin.nix index 7f07b458..ad1ab8fb 100644 --- a/modules/nix/nix-darwin.nix +++ b/modules/nix/nix-darwin.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let nix-tools = pkgs.callPackage ../../pkgs/nix-tools { @@ -7,22 +7,30 @@ let nixPackage = config.nix.package; }; + darwin-uninstaller = pkgs.callPackage ../../pkgs/darwin-uninstaller { }; + inherit (nix-tools) darwin-option darwin-rebuild darwin-version; in { - config = { + options = { + system.includeUninstaller = lib.mkOption { + type = lib.types.bool; + internal = true; + default = true; + }; + }; + config = { environment.systemPackages = [ # Include nix-tools by default darwin-option darwin-rebuild darwin-version - ]; + ] ++ lib.optional config.system.includeUninstaller darwin-uninstaller; system.build = { inherit darwin-option darwin-rebuild darwin-version; }; - }; } diff --git a/pkgs/darwin-uninstaller/configuration.nix b/pkgs/darwin-uninstaller/configuration.nix index 96a2165a..6487774b 100644 --- a/pkgs/darwin-uninstaller/configuration.nix +++ b/pkgs/darwin-uninstaller/configuration.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ lib, ... }: with lib; diff --git a/pkgs/darwin-uninstaller/default.nix b/pkgs/darwin-uninstaller/default.nix index ca7be489..94c07494 100644 --- a/pkgs/darwin-uninstaller/default.nix +++ b/pkgs/darwin-uninstaller/default.nix @@ -1,18 +1,17 @@ -{ stdenv, nix, pkgs, nix-darwin }: +{ stdenv, lib, pkgs }: let - configuration = builtins.path { - name = "nix-darwin-uninstaller-configuration"; - path = ./.; - filter = name: _type: name != toString ./default.nix; + uninstallSystem = import ../../eval-config.nix { + inherit lib; + modules = [ + ./configuration.nix + { + nixpkgs.source = pkgs.path; + nixpkgs.hostPlatform = pkgs.system; + system.includeUninstaller = false; + } + ]; }; - - nixPath = pkgs.lib.concatStringsSep ":" [ - "darwin-config=${configuration}/configuration.nix" - "darwin=${nix-darwin}" - "nixpkgs=${pkgs.path}" - "$NIX_PATH" - ]; in stdenv.mkDerivation { @@ -62,10 +61,7 @@ stdenv.mkDerivation { esac fi - export nix=${nix} - export NIX_PATH=${nixPath} - system=$($nix/bin/nix-build '' -A system) - $system/sw/bin/darwin-rebuild switch + ${uninstallSystem.system}/sw/bin/darwin-rebuild activate if test -L /run/current-system; then sudo rm /run/current-system