-
I am currently working with a larger monorepo with a cargo workspace (+20 crates). However, for my flake I want to ignore most of them and just focus on a select few. How could I do this with crane? The basic hierarchy of the monorepo is:
Now, I'd like that people can do the following:
Thank you for the tool! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @TheNeikos! The short answer is:
On to the longer/more detailed responses:
This is entirely achievable through the dev shell as long as you have the right tools declared. When you run
You can definitely use crane to build the CLI tool (so that the binary is available to NixOS modules for example). If the workspace has a ton of other crates that you don't care about being available to other Nix derivations you can always customize the exact cargo command that the build invokes. Here's a rough example: # This whole example will effectively only build the `foo_cli` crate (and any workspace crates it depends on)
packages.foo_cli = craneLib.buildPackage {
src = ./.;
cargoBuildCommand = "cargo build --release -p foo_cli";
}; The downside to this approach is that if you make a change to, say, the But if it is, you could move all the foo crates into their own subdirectory and change the example to: packages.foo_cli = craneLib.buildPackage {
src = ./fooCrates; # This line changed!
cargoBuildCommand = "cargo build --release -p foo_cli";
}; That way Nix will ignore changes to the I have some ideas on having crane analyze the workspace layout and automatically construct the right derivations so that each crate can be built with only the sources it relies on so unrelated changes do not cause mass rebuilds, but so far that's all it has been, ideas ;) Hope this helps in the meantime! |
Beta Was this translation helpful? Give feedback.
-
I think I've solved this for myself entirely. The only downside is that each application in a workspace will require specifying which directories it is being built from. I guess in theory it would be possible for some more complex automation to figure it out, possibly by calling some So, in I possibly could write it more cleanly, but it's a PoC and my Nix-fu is still weak. |
Beta Was this translation helpful? Give feedback.
Hi @TheNeikos! The short answer is:
On to the longer/more detailed responses:
This is entirely achievable through the dev shell as long as you have the right tools declared. When you run
cargo build/check
in your terminal you aren't bound by Nix's sandbox, cargo will happily put the artifacts in…