From eac3546d502522816833d90ac5f8854259d5adff Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 29 May 2024 19:57:58 -0600 Subject: [PATCH] package: return from shellHook correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If our shellHook is being run from a nested nix-shell (see 7a12bc200ยน), then (I think) it is run from a bash function due to the nesting, then `return` is correct. If its `eval`'d though, then there isn't really a correct way to early exit. So we can just unconditionally be executed in a function. Basically, we have IIFE at home. [1]: 7a12bc2007accb5022037b5a04b0e5475a8bb409 Change-Id: Iacad25cbbf66cde2911604e6061e56ad6212af7e --- package.nix | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/package.nix b/package.nix index 70db7eb22..22cf11cd9 100644 --- a/package.nix +++ b/package.nix @@ -441,32 +441,36 @@ stdenv.mkDerivation (finalAttrs: { shellHook = '' # don't re-run the hook in (other) nested nix-shells - if [[ $name != lix-shell-env ]]; then - return; - fi + function lixShellHook() { + if [[ $name != lix-shell-env ]]; then + return; + fi - PATH=$prefix/bin:$PATH - unset PYTHONPATH - export MANPATH=$out/share/man:$MANPATH + PATH=$prefix/bin:$PATH + unset PYTHONPATH + export MANPATH=$out/share/man:$MANPATH - # Make bash completion work. - XDG_DATA_DIRS+=:$out/share + # Make bash completion work. + XDG_DATA_DIRS+=:$out/share - ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} - # Allow `touch .nocontribmsg` to turn this notice off. - if ! [[ -f .nocontribmsg ]]; then - cat ${contribNotice} - fi + ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} + # Allow `touch .nocontribmsg` to turn this notice off. + if ! [[ -f .nocontribmsg ]]; then + cat ${contribNotice} + fi - # Install the Gerrit commit-msg hook. - # (git common dir is the main .git, including for worktrees) - if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then - echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 - mkdir -p "$gitcommondir/hooks" - curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg - chmod u+x "$gitcommondir/hooks/commit-msg" - fi - unset gitcommondir + # Install the Gerrit commit-msg hook. + # (git common dir is the main .git, including for worktrees) + if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then + echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 + mkdir -p "$gitcommondir/hooks" + curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg + chmod u+x "$gitcommondir/hooks/commit-msg" + fi + unset gitcommondir + } + + lixShellHook ''; } );