Skip to content

nix: Use a stable, non-/tmp dir for mkEdaShell ldPreload wrappers - #207

Merged
machshev merged 2 commits into
lowRISC:mainfrom
machshev:eda-stable-wrapdir
Oct 12, 2026
Merged

machshev merged 2 commits into
lowRISC:mainfrom
machshev:eda-stable-wrapdir

Conversation

@machshev

Copy link
Copy Markdown
Collaborator

Problem

mkEdaShell's ldPreload: gmp capability (used for Vivado) wrote its wrapper scripts into a fresh mktemp -d dir under /tmp on every shell start and prepended it to PATH.

OpenTitan's @nonhermetic Bazel repo records the directory vivado was found in, and the FuseSoC synth action runs in a sandbox with a private /tmp (--incompatible_sandbox_hermetic_tmp, the default since Bazel 7). The wrapper is invisible there, so bitstream builds fail:

make: vivado: No such file or directory
make: *** [Makefile:8: lowrisc_systems_chip_earlgrey_cw340_0.1.xpr] Error 127

The random path also changes PATH on every new shell, which re-runs @nonhermetic and invalidates cached bitstreams.

Fix

  • Write wrappers to ${XDG_CACHE_HOME:-$HOME/.cache}/lowrisc-eda/wrappers/<vendor>-<tool>-<hash>, keyed on the tool home and gmp lib path, so the location is stable across shells and visible inside the Bazel sandbox.
  • Write each wrapper to a temp file and rename it into place, so concurrently starting shells never see a partial file.
  • Resolve the real binaries with the wrapper dir stripped from PATH, so a re-sourced profile can't generate a wrapper that execs itself or add the dir to PATH twice.

Testing

  • nix fmt -- --check and nix-instantiate --parse pass.
  • Ran the wrapper logic on its own: the path is stable, re-sourcing doesn't loop or duplicate PATH, and no temp files are left behind.
  • In OpenTitan with nix run --override-input lowrisc-nix path:<this branch> .#eda: vivado resolves to ~/.cache/lowrisc-eda/wrappers/xilinx-vivado-<hash>/vivado, which preloads the Nix gmp and execs the 2021.1 install. vivado -version runs.
  • Not yet run: a full Bazel bitstream build.

🤖 Generated with Claude Code

The gmp LD_PRELOAD wrappers (e.g. for Vivado) were written to a fresh
`mktemp -d` dir under /tmp on every shell start and prepended to PATH.
Bazel-based flows such as OpenTitan's record the directory a tool was
found in and run actions in a sandbox with a private /tmp
(--incompatible_sandbox_hermetic_tmp), so the wrapper was invisible and
the build failed with "vivado: No such file or directory". The random
path also changed PATH on every new shell, invalidating cached results
such as bitstreams.

Write the wrappers to
$XDG_CACHE_HOME/lowrisc-eda/wrappers/<vendor>-<tool>-<hash>, keyed on
the tool home and gmp library, writing each one atomically. Resolve the
real binaries with that dir stripped from PATH so a re-sourced profile
cannot generate a self-exec'ing wrapper or duplicate the PATH entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: David James McCorrie <james.mccorrie@lowrisc.org>
Comment thread lib/edaShell.nix
# a sandbox with a private /tmp, and a per-shell path would change
# PATH (and so invalidate cached results) on every new shell. Key it
# on everything the wrapper contents depend on.
wrapdir="''${XDG_CACHE_HOME:-$HOME/.cache}/lowrisc-eda/wrappers/$v-$t-$(printf '%s\n' "$home" "${gmpLib}" | sha256sum | cut -c1-16)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: I don't think this directory will be automatically cleaned-up like /tmp is, so these wrapper files will accumulate. Probably not an issue, but slightly ugly

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it won't be cleaned automatically. A new dir only appears when the tool home or the gmp store path changes (a Vivado version change or a nixpkgs bump), and each holds a few tiny scripts, so growth is very slow. I'd rather not prune automatically: a still-open shell may have an older dir on its PATH, and deleting it would break vivado there. rm -rf ~/.cache/lowrisc-eda is always safe with no shells open. Happy to add a note on that to README-eda.md if you think it's worth it.

Comment thread lib/edaShell.nix Resolved

@hcallahan-lowrisc hcallahan-lowrisc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think the PATH-handling could be slightly improved but this should work as-is for the issue encountered

The pathDirs loop prepended $home/<dir> to PATH unconditionally, so
re-sourcing the profile in an existing shell (nested `bash -l`,
`source /etc/profile`, ...) added another copy on each source. Prepend
via a helper that first drops any existing occurrence, and reuse it for
the ldPreload wrapper dir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: David James McCorrie <james.mccorrie@lowrisc.org>
@machshev
machshev added this pull request to the merge queue Oct 12, 2026
Merged via the queue into lowRISC:main with commit 42526a6 Oct 12, 2026
3 checks passed
@machshev
machshev deleted the eda-stable-wrapdir branch October 12, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants