From ebca0c23c95cc2d2c75b3c3a290fa99a886b9738 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 5 Nov 2024 02:48:25 +1100 Subject: [PATCH] uninstaller: switch to `writeShellApplication` By not defining a `shellHook`, `nix-shell -A uninstaller` and `nix-shell -A uninstaller.check` no longer work. --- .github/workflows/test.yml | 18 ++++-- pkgs/darwin-uninstaller/default.nix | 95 ++++++++++++----------------- 2 files changed, 50 insertions(+), 63 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce176eb..e786b4a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,9 +66,12 @@ jobs: darwin-rebuild switch -I darwin=. - name: Test uninstallation of nix-darwin run: | - export NIX_PATH=$HOME/.nix-defexpr/channels - nix-shell -A uninstaller - nix-shell -A uninstaller.check + nix run .#darwin-uninstaller \ + --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} \ + --extra-experimental-features "nix-command flakes" + nix run .#darwin-uninstaller.tests.uninstaller \ + --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} \ + --extra-experimental-features "nix-command flakes" - name: Debugging tmate session if: ${{ failure() }} uses: mxschmitt/action-tmate@v3 @@ -111,9 +114,12 @@ jobs: darwin-rebuild switch -I darwin=. - name: Test uninstallation of nix-darwin run: | - export NIX_PATH=$HOME/.nix-defexpr/channels - nix-shell -A uninstaller - nix-shell -A uninstaller.check + nix run .#darwin-uninstaller \ + --override-input nixpkgs nixpkgs/nixpkgs-unstable \ + --extra-experimental-features "nix-command flakes" + nix run .#darwin-uninstaller.tests.uninstaller \ + --override-input nixpkgs nixpkgs/nixpkgs-unstable \ + --extra-experimental-features "nix-command flakes" - name: Debugging tmate session if: ${{ failure() }} uses: mxschmitt/action-tmate@v3 diff --git a/pkgs/darwin-uninstaller/default.nix b/pkgs/darwin-uninstaller/default.nix index a82974e..5159c2c 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 @@ -50,15 +34,15 @@ stdenv.mkDerivation { echo >&2 " - restore daemon service from nix installer (only when this is a multi-user install)" 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 @@ -83,29 +67,26 @@ stdenv.mkDerivation { 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 + 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 ''; }; }