Add Nix Flake devshell + direnv#432
Open
thebrandonlucas wants to merge 1 commit into
Open
Conversation
thebrandonlucas
commented
Jul 16, 2026
|
|
||
| channel = "1.83.0" # check ^^^ when changing this | ||
| components = ["rust-analyzer"] | ||
| components = ["rust-analyzer", "llvm-tools-preview"] |
Author
There was a problem hiding this comment.
Support host stripping performed in scripts/build.py
thebrandonlucas
commented
Jul 16, 2026
Comment on lines
+120
to
145
| def rust_target_is_installed(rust_target: str) -> bool: | ||
| result = subprocess.run( | ||
| ["rustc", "--print", "target-libdir", "--target", rust_target], | ||
| check=False, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.DEVNULL, | ||
| text=True, | ||
| ) | ||
| return result.returncode == 0 and Path(result.stdout.strip()).is_dir() | ||
|
|
||
|
|
||
| def install_rust_target(rust_target: str, *, required: bool = False) -> None: | ||
| if rust_target_is_installed(rust_target): | ||
| return | ||
|
|
||
| if shutil.which("rustup") is None: | ||
| message = ( | ||
| f"Rust target {rust_target} is not installed and rustup is unavailable; " | ||
| "enter `nix develop` or install the target manually" | ||
| ) | ||
| if required: | ||
| raise SystemExit(message) | ||
| print(f"warning: {message}") | ||
| return | ||
|
|
||
| run("rustup", "target", "add", rust_target, check=required) |
Author
There was a problem hiding this comment.
Previously we assumed Rust targets were always managed bu rustup and unconditionally ran this every time, even if the target was already installed. Nix manages this via the nix store and does not use this rustup. So this would fail with rustup: command not found even if all the targets were available. By using rustc to ask where the target libraries should be, then verifying it exists there via result.returncode == 0 and Path(result.stdout.strip()).is_dir(), we maintain backward compat for non-nix users.
thebrandonlucas
force-pushed
the
nix-dev-shell
branch
from
July 16, 2026 14:33
f6a25cf to
09001ed
Compare
thebrandonlucas
marked this pull request as ready for review
July 16, 2026 14:33
Restores and updates the old flake.nix to add a post-Zig migration devshell. Also adds direnv for automatic env loading upon entering the directory. Since Zig compiler has no stable release yet, this uses roc-overlay to always use latest nightly roc compiler, so the user doesn't have to continuously download nightly. Adds checks to scripts/build.py to not download the rust toolchain on every build if it already exists, and to allow interop with Nix users and backward compatibility for non Nix users. Also updates CONTRIBUTING.md with new Nix usage section. docs: note required Nix features
thebrandonlucas
force-pushed
the
nix-dev-shell
branch
from
July 16, 2026 14:53
c9088af to
b6f7f5b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
flake.nixwas removed from #413 to avoid bundling another change into that large PR.I've added back the flake.nix as mentioned here removing unnecessary tools and adding new ones (Zig 16, etc.). One problem I ran into was that while the old
flake.nixwas able to just use the standard Roc compiler from unstable nixpkgs, that doesn't work for the new compiler because it's unreleased on nixpkgs. To solve that here we'd have to pin a particular nightly release and just keepbasic-cliup to date with it, modifying the flake with every incompatibility.That seemed like too much overhead to be worth it, and I felt that this must be a general pain point for other projects, so I created roc-overlay to solve this problem for this and other projects that wish to use it. It's modeled after zig-overlay and is useful for any project which intends to keep up with the latest nightly compilers (or pin themselves to previous ones). More here.
Updated
CONTRIBUTING.mdto add the section about using Nix for the development environment. We could probably also take advantage of this to simplify CI (and have a single source of truth) onceroc-overlayproves it's mettle a bit more.I also added direnv which is a great convenience tool for automatically loading dev environments upon shell entry. It requires manual activation by the user once, then subsequently loads the shell with all appropriate dependencies thereafter.