Skip to content

Add option to allow users to inspect the system-specific install script in $tempDir after failed installations #4979

@ambirdsall

Description

@ambirdsall

the error which prompted this issue

While attempting to install on macOS x86, I ran into a strange edge case of my own making: as a personal in-joke, I had an emacsclient wrapper script at $HOME/bin/ed, which was invoked instead of /bin/ed by printf "\$a\nLABEL=%s /nix apfs rw,nobrowse\n.\nwq\n" "$label" | EDITOR=ed sudo vifs, derailing my installation. While this specific error was extremely idiosyncratic and not worth fixing per se (I suppose it could also download a statically-linked ed binary alongside the system-specific install script, but that seems excessive), the install script's unconditional invocation of the cleanup function automatically erased the information I needed to diagnose the problem at all; it would be lovely if there were a way to opt out of the automatic rm -rf $tempDir on failure, to enable debugging issues with the inner install script.

To debug this as-is, I had to

  1. run something like curl -L https://nixos.org/nix/install > /tmp/nix-installer
  2. manually edit the script to disable the cleanup function
  3. run /tmp/nix-installer --darwin-use-unencrypted-nix-store-volume --daemon to fetch the nested install script, wait for it to fail again
  4. read through the files in $tempDir (side note: thanks to whoever wrote the statement that printed the tempDir path to my terminal) until I found the issue

something which would have made my life a bit nicer in that moment

This is a naive and partial sketch of the approach that occurred to me; I don't know the ins and outs of trapping posix signals or script lifecycles well enough to write a fully correct or robust version.

SCRIPT_ARGS="$@"
PRESERVE_STATE_ON_EXIT=0

while [ $# -gt 0 ]; do
    case $1 in
        --preserve-state-on-exit)
            PRESERVE_STATE_ON_EXIT=1
            ;;
        *)
            ;;
    esac
    shift
done

# define oops, umask, create $tmpDir

cleanup() {
    rm -rf "$tmpDir"
}
maybe-cleanup() {
    if [ $? -eq 0 ]; then
        cleanup
    else
        exit $?
    fi
}

trap cleanup INT QUIT TERM

if [ $PRESERVE_STATE_ON_EXIT -eq 1 ]; then
    trap maybe-cleanup EXIT
else
    trap cleanup EXIT
fi

# introspect system and fetch/verify/unpack script

"$script" "$SCRIPT_ARGS"

The a possibly lighterweight alternative would be to print the generated curl command for the user's system to STDOUT (possibly only on error) so they can more easily dig in if things go wrong with the inner install script.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions