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
- run something like
curl -L https://nixos.org/nix/install > /tmp/nix-installer
- manually edit the script to disable the
cleanup function
- run
/tmp/nix-installer --darwin-use-unencrypted-nix-store-volume --daemon to fetch the nested install script, wait for it to fail again
- 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.
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/edbyprintf "\$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-linkededbinary alongside the system-specific install script, but that seems excessive), the install script's unconditional invocation of thecleanupfunction 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 automaticrm -rf $tempDiron failure, to enable debugging issues with the inner install script.To debug this as-is, I had to
curl -L https://nixos.org/nix/install > /tmp/nix-installercleanupfunction/tmp/nix-installer --darwin-use-unencrypted-nix-store-volume --daemonto fetch the nested install script, wait for it to fail again$tempDir(side note: thanks to whoever wrote the statement that printed the tempDir path to my terminal) until I found the issuesomething 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.
The a possibly lighterweight alternative would be to print the generated
curlcommand 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.