devshell: Fix usage with nix-shell

Since d0190cff6f, the `justfile` uses
`$out` from the environment as an argument to `--prefix` in its `meson`
invocation.

The `$out` variable is...  A bit spicy to use since its semantics change
depending on whether `nix develop` or `nix-shell` is used.

In a `nix develop` shell, a directory *relative to PWD* (and not
relative to the Nix expression) is exported. In a `nix-shell`, the
`$out` used comes from the derivation.

The alternative to this change is to make the `justfile` use a variable
name that would not conflict with a `nix-shell` and `nix develop` shell.
Since it wants to use that value for the `outdir` variable, this would
be the name I would pick first.

I chose to instead work around the issue within the `nix-shell` since
this would be breaking the existing interface. As tenuous as it is.

Change-Id: I64cd5fd85345457e14880cb133e9ddafd55a25da
This commit is contained in:
Samuel Dionne-Riel
2026-07-01 11:02:38 +00:00
committed by Samuel Dionne-Riel (work)
parent a92e4b5c42
commit cf1e565a0a
+6
View File
@@ -906,6 +906,12 @@ stdenv.mkDerivation (finalAttrs: {
++ finalAttrs.checkInputs;
shellHook = ''
# Make `nix-shell` use a PWD-relative dir for `out`, emulating `nix develop`.
# The original `out` path is never going to be relevant, and breaks assumptions for the justfile.
if [[ "$out" =~ ^${builtins.storeDir}/ ]]; then
export out="$PWD/outputs/out"
fi
# don't re-run the hook in (other) nested nix-shells
function lixShellHook() {
# n.b. how the heck does this become -env-env? well, `nix develop` does it: