chore: switch to crate2nix - #2719
Conversation
|
Hi @mightyiam , this PR is ready for review. |
mightyiam
left a comment
There was a problem hiding this comment.
What about the experimental crate2nix json api?
Will investigate the experimental JSON output separately and report back in the discussion. |
db377d9 to
0917330
Compare
Still pending, will try it after resolving the current comments. If it simplifies the approach, happy to switch to it entirely. |
0917330 to
1aab0dc
Compare
1aab0dc to
9cc159c
Compare
mightyiam
left a comment
There was a problem hiding this comment.
It seems that this change results in our dev shell including some rust crate derivations. Can that be avoided?
It seems that this change results in tests not being run during the build. Rust tests | crate2nix.
|
Confirmed, |
|
Investigated the test failure. The existing integration tests in
For now I've removed |
9cc159c to
08467a6
Compare
Does that feel reasonable to you? |
Yes, that feels reasonable. The test infrastructure issue is real and worth fixing properly in a follow-up, the existing integration tests call |
|
The change you are currently suggesting disables the running of all of the program's cargo tests during |
You're right, that is a regression. Two options I can see:
Which would you prefer? |
|
Sorry, I'm not sure what you mean by "once the test infrastructure is ready". What infrastructure is that, please? What is not ready? Something about |
You're right, I overcomplicated it. The tests call |
|
Adding |
99f6ee9 to
391729a
Compare
570cf68 to
354eb67
Compare
| @@ -1,44 +1,31 @@ | |||
| use std::{io::Write, process::Command, process::Stdio}; | |||
|
|
|||
There was a problem hiding this comment.
No, no intentional. Will restore it.
| let mut child = Command::new("cargo") | ||
| .arg("run") | ||
| .arg("--") | ||
| let mut child = Command::new(env!("CARGO_BIN_EXE_statix")) |
There was a problem hiding this comment.
Can this be made a precursor PR?
There was a problem hiding this comment.
Yes, will extract the _utils.rs change into a precursor PR, then rebase this one on top of it.
| clippy = pkgs.rustPlatform.buildRustPackage { | ||
| pname = "statix-clippy"; | ||
| version = "0.6.0-git"; | ||
| inherit src; | ||
| cargoLock.lockFile = root + "/Cargo.lock"; | ||
| RUSTFLAGS = "-D warnings"; | ||
| nativeBuildInputs = [ pkgs.clippy ]; | ||
| buildPhase = "cargo clippy --all-targets --all-features"; | ||
| installPhase = "touch $out"; | ||
| doCheck = false; | ||
| }; |
There was a problem hiding this comment.
Can clippy be based on crate2nix as well?
There was a problem hiding this comment.
Yes, will switch clippy to use pkgs.statix-workspace, the workspace already has all crates built, so clippy can run against those derivations without needing a separate buildRustPackage
There was a problem hiding this comment.
Crate2nix doesn't expose a clippy mechanism through its build attributes, it builds crates via rustc derivations with no clippy hook. The rustPlatform.buildRustPackage approach is the right tool for running clippy; I've updated it to use the shared pkgs.statix-src from packages/src.nix so there's no duplication with the crate2nix builds.
There was a problem hiding this comment.
Doesn't this section demonstrate a useClippy = true? Isn't that what we are looking for?
| cargoNix = crate2nixTools.generatedCargoNix { | ||
| name = "statix"; | ||
| src = lib.fileset.toSource { | ||
| root = ../.; | ||
| fileset = lib.fileset.unions [ | ||
| (lib.fileset.fileFilter ( | ||
| file: | ||
| lib.any lib.id [ | ||
| (file.name == "Cargo.toml") | ||
| (file.hasExt "rs") | ||
| (file.hasExt "snap") | ||
| ] | ||
| ) ../.) | ||
| ../Cargo.lock | ||
| ../insta.yaml | ||
| ]; | ||
| }; |
There was a problem hiding this comment.
It seems that this expression exists twice. Is that intentional?
There was a problem hiding this comment.
Yes, not intentional. Will deduplicate, the fileset can be defined once and referenced in both, probably by moving it into the overlay or having statix-workspace re-export it for statix.nix to use.
354eb67 to
76de74b
Compare
| clippy = pkgs.rustPlatform.buildRustPackage { | ||
| pname = "statix-clippy"; | ||
| version = "0.6.0-git"; | ||
| inherit src; | ||
| cargoLock.lockFile = root + "/Cargo.lock"; | ||
| RUSTFLAGS = "-D warnings"; | ||
| nativeBuildInputs = [ pkgs.clippy ]; | ||
| buildPhase = "cargo clippy --all-targets --all-features"; | ||
| installPhase = "touch $out"; | ||
| doCheck = false; | ||
| }; |
There was a problem hiding this comment.
Doesn't this section demonstrate a useClippy = true? Isn't that what we are looking for?
| meta = { | ||
| mainProgram = "statix"; | ||
| description = "Lints and suggestions for the Nix programming language"; | ||
| homepage = "https://github.com/molybdenumsoftware/statix"; | ||
| license = lib.licenses.mit; |
There was a problem hiding this comment.
Do we lose these or are they automatically populated from Cargo.toml?
There was a problem hiding this comment.
They're lost, crate2nix only auto-populates mainProgram. description, homepage, and license need to be added back via overrideAttrs. Will fix.
You're right, |
76de74b to
f0e5ff2
Compare
mightyiam
left a comment
There was a problem hiding this comment.
Please review thoroughly before submitting.
| testPreRun = '' | ||
| export INSTA_SNAPSHOT_DIR=${root}/bin/tests/snapshots | ||
| ''; |
There was a problem hiding this comment.
The integration tests use insta::assert_snapshot! which looks for snapshot files relative to the crate source location. In the Nix build sandbox, the working directory isn't the source tree, so insta can't find the snapshots without being explicitly pointed at them via INSTA_SNAPSHOT_DIR.
There was a problem hiding this comment.
If
The integration tests use insta::assert_snapshot! which looks for snapshot files relative to the crate source location
it sounds like if that is the case, there should be no problem finding them. Are you sure of that explanation?
| { lib }: | ||
| lib.fileset.toSource { | ||
| root = ../.; | ||
| fileset = lib.fileset.unions [ | ||
| (lib.fileset.fileFilter ( | ||
| file: | ||
| lib.any lib.id [ | ||
| (file.name == "Cargo.toml") | ||
| (file.hasExt "rs") | ||
| (file.hasExt "snap") | ||
| ] | ||
| ) ../.) | ||
| ../Cargo.lock | ||
| ../insta.yaml | ||
| ]; | ||
| } |
There was a problem hiding this comment.
Perhaps this should be inlined?
There was a problem hiding this comment.
Happy to inline it , though that means accepting the duplication between the two files rather than avoiding it. Is that the preference, or should one file reference the other's src? Asking because the original concern was about the expression appearing twice.
There was a problem hiding this comment.
Happy to inline it , though that means accepting the duplication between the two files rather than avoiding it. Is that the preference, or should one file reference the other's src? Asking because the original concern was about the expression appearing twice.
What about this? @mightyiam ?
There was a problem hiding this comment.
I think as soon as the duplicate code is removed, this should be inlined into a single remaining position.
| cargoNix = crate2nixTools.generatedCargoNix { | ||
| name = "statix"; | ||
| src = statix-src; |
There was a problem hiding this comment.
You're right, generatedCargoNix is called identically in both files, generating the same derivation twice. The fix is to expose cargoNix itself via the overlay and have both files use it. Will restructure.
|
@mightyiam , I am waiting for your answers, it changes the structure significantly. |
|
I thought I was waiting for you. You wrote this: |
I am waiting for your answers on my responses under your latest feedbacks |
|
As is, I see duplicate code. |
f0e5ff2 to
2ba8532
Compare
| @@ -1,11 +1,14 @@ | |||
| { ... }: | |||
| testPreRun = '' | ||
| export INSTA_SNAPSHOT_DIR=${root}/bin/tests/snapshots | ||
| ''; |
There was a problem hiding this comment.
If
The integration tests use insta::assert_snapshot! which looks for snapshot files relative to the crate source location
it sounds like if that is the case, there should be no problem finding them. Are you sure of that explanation?
| clippy = statixBuild.override { | ||
| crateOverrides = pkgs.defaultCrateOverrides // { | ||
| statix = _: { | ||
| useClippy = true; | ||
| RUSTFLAGS = "-D warnings"; | ||
| }; | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Instead of having an additional check, can we have only one check, and that is simply the package, itself, in which clippy is used?
There was a problem hiding this comment.
Makes sense, will move useClippy = true and RUSTFLAGS = "-D warnings" into the package build via crateOverrides in packages/statix.nix, so checks.statix = pkgs.statix covers clippy automatically. No separate check needed.
2ba8532 to
69b9bcf
Compare
You're right, tested without it and the tests pass. Insta finds the snapshots via |
b7e7db6 to
35e640b
Compare
| @@ -1,11 +1,13 @@ | |||
| { | |||
| _: { | |||
There was a problem hiding this comment.
Please review your changes as best as you can before expecting anyone else to review them. Such trivial mistakes can be avoided.
There was a problem hiding this comment.
Understood. I should have caught that before pushing. I'll be more careful.
There was a problem hiding this comment.
This unrelated and undesireable change is still present.
| { | ||
| _: { | ||
| perSystem = | ||
| { pkgs, ... }: | ||
| let | ||
| statixBuild = pkgs.statix-workspace.workspaceMembers.statix.build; | ||
| in | ||
| { | ||
| treefmt.settings.global.excludes = [ "bin/tests/data/*.nix" ]; | ||
| checks.build = pkgs.statix; | ||
| checks = { | ||
| inherit (pkgs) statix; | ||
| statix-tests = statixBuild.override { | ||
| runTests = true; | ||
| }; | ||
| }; | ||
| }; | ||
| } |
There was a problem hiding this comment.
Does this file need to change? Perhaps if the runTests=true is in the one single derivation, this file can remain the same?
There was a problem hiding this comment.
If runTests = true is in the package itself alongside useClippy = true, then checks.build = pkgs.statix covers everything and flake-parts/statix.nix doesn't need to change. Will move runTests = true into packages/statix.nix and revert flake-parts/statix.nix to its pre-PR state.
35e640b to
1d1b084
Compare
mightyiam
left a comment
There was a problem hiding this comment.
Do you think that a pull request should be freshly rebased at the time review is requested?
| @@ -1,11 +1,13 @@ | |||
| { | |||
| _: { | |||
There was a problem hiding this comment.
This unrelated and undesireable change is still present.
| crateOverrides = defaultCrateOverrides // { | ||
| statix = _: { | ||
| useClippy = true; | ||
| RUSTFLAGS = "-D warnings"; |
There was a problem hiding this comment.
Should this be achieved using capLints instead?
There was a problem hiding this comment.
I am not aware capLints as an idiomatic option. I will investigate and switch to it.
| statix-cargo-nix = prev.callPackage ./packages/cargo-nix.nix { }; | ||
| statix = prev.callPackage ./packages/statix.nix { }; | ||
| statix-workspace = prev.callPackage ./packages/statix-workspace.nix { }; | ||
| statix-vim = prev.callPackage ./packages/statix-vim.nix { }; |
There was a problem hiding this comment.
Does exposing these two new intermediate packages provide any value to developers or users? Should they exist as local binding in packages/statix.nix instead?
There was a problem hiding this comment.
Neither of these has value outside of being inputs to building statix itself. So, I think they should exist as local binding in packages/statix.nix.
I agreed with you because, these are implementation details that shouldn't leak into the public overlay.
Yes. It is a good practice. I will take note of that going forward |
|
I removed it, I am wondering how it shows again. |
|
Is this waiting on me? |
Switches the
statixpackage build fromrustPlatform.buildRustPackagetocrate2nix, which builds each crate as a separate Nix derivation enabling more granular caching.Changes:
github:nix-community/crate2nixas aflake = falseinputinputsthrough the overlay socrate2nixSrcis available tocallPackagepackages/statix.nixto usetools.generatedCargoNix(IFD).Cargo.nixis generated at build time rather than checked inallow-import-from-derivation= false fromnixConfigsince IFD is now requiredThe
statix-vimpackage is unaffected.