-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nix development environment #100
base: develop
Are you sure you want to change the base?
Conversation
Thanks for this! I took a quick look, and indeed it seems like the integration tests pass if I run with Note that with this PR, the tests fail at |
According to this Rust's |
Hey there. I don't know Rust but I kicked around with the errors, putting println statements like a noob. It's a direct Rust FYI, Nix's |
Thanks!
The executable path is "hard-coded" in the tests here at compile time, but that didn't turn out to be the issue, see my comment in #93.
Haha, that's exactly how I found out the root cause of the issue. Btw, when running with |
I investigated a bit, and it seems like one way to enable The Now, even if the |
The other user suggested the I'm not sure why You asked how you could build the package without rebuilding the dependencies every time. The answer is |
Yeah, I will check out I have pushed my attempt at adding
Ah I see, yeah I would prefer to keep the build to be Cargo-based. While searching for this, I also found naersk and crane which seem to be also doing something like this, but without overriding Cargo.lock? I tried to add naersk to the flake.nix, but again I didn't know how to do it with my zero Nix experience (I even asked ChatGPT). |
Okay, I was able to run the tests through This works as expected and makes
to one of the failing tests, when running without
which I suspected was the cause of the issue. With the
which seems promising but the tests still fail. I am really at a loss here. I also tried checkPhase = ''
${pkgs.faketty}/bin/faketty cargo test
'';
buildInputs = [
faketty
]; but the result is the same. |
|
Okay,
Yeah, let's not struggle with this further. You can either disable all of the integration tests with
This way, new tests will be run if they are added. OTOH, integration tests will likely always run the program and run into this same tty issue. For now, let's not keep the Nix config files in this repo, I think they should be in nixpkgs instead. |
Okay, I couldn't help myself but investigate a bit further, and I think I have a solution. I understand now why adding More interestingly, the reason the buildInputs = [
ncurses # provides the tput command needed for integration tests
]
checkPhase = ''
export PATH=${pkgs.ncurses}/bin:$PATH
cargo test
'' (see abdc4e1. This is still building on the original I saw some issues on the crossterm tracker that they want to get rid of the |
Ok, I've pushed a I've left some extra features from the default template if you're interested. One is Darwin build support, which I can't test. The other is a lot of checks (formatting, dependencies with security issues, etc) which can be run with I also tried to make the flake able to cross-compile for other architectures, as I'd heard Nix can handle cross compiling fairly well. But as you can see in this example the Rust tooling needs lots of massaging to work and it would require putting parameters absolutely everywhere. |
Thank you, that sounds great! I really appreciate your work. Can this configuration be used in nixpkgs? As I mentioned, I would prefer if it lived there. |
After looking at Nixpkgs, it turns out that external flakes are not allowed, meaning Crane can't be used there. Details here. So my hopes of porting these changes back to NixPkgs are dashed. As to the flake being in this repo, notice it contains a lot of non-package conveniences (toolchain, formatting, and it can even be extended to give shell aliases and such). IMO the main advantage of having the flake in your repo is being able to use it to run tests, as you've seen it lets you catch bugs that don't show up in the regular build. Let me know whether you want to keep the flake or not, or if there's something you'd like to see changed. |
Hm, that's unfortunate. I suppose the same applies for naersk, or other libs for building Rust projects? But maybe for the build on the nixpkgs server that caching doesn't help anyway, or does it? In any case, thank you very much for this flake. Do you mind if we leave it out of this repo for now? We can keep your patch/branch around in this PR if it's needed for testing. |
This is a Nix dev environment that you can run on any OS with Nix installed. You could accept the PR, but if you don't want the Nix files in it, you can just check out my branch until you track down the bug. :)
Usage:
nix develop .#
and get a shell (more sandboxed than the direnv one, occasionally this helps with bugs).nix run .# -- (args)
tere
command in it withnix shell .#
nix build .#
.File meanings: All the config for the dev environment is kept in
flake.nix
.flake.lock
is what makes it reproducible, it will always load the same Rust toolchain until you update it withnix flake update
.In revision 5a03e56 I removed 3 optional files if you're interested. They're 2 files for Nix backwards compatibility, and one with a GitHub workflow for automatic package building.
The failures: Something about Nix's
buildRustPackage
is leading to the failures (the Arch builds are failing in a similar way). You'll notice there's no failure when testing in the dev shell withcargo test
, or in my earlier revision 5a03e56 that usednaersk
's Rust builder.Note, I tried both
dontUseCargoParallelTests = true;
andcheckType = "debug";
, neither fixed the test failures. The docs forbuildRustPackage
are here, and (should things get really dire) the source code is here, preferably that won't be needed at all :)