Skip to content

Incremental builds of dependencies #201

@Ma27

Description

@Ma27

First of all, thanks a lot for this! This is a big step towards how I'd like to see Nix being used for development!

I have a question and I'd like to get some feedback on whether this is actually reasonable. If I have the time for that, I may file a PR on my own later on if that's the case.

When I e.g. add a dependency to my Cargo.toml and run cargo build, only the newly added (or existing, but updated) crates will be rebuilt. When I do a nix build instead, all of the deps are rebuilt in the pname-deps drv. I'm wondering if it'd be somehow reasonable & possible to split the pname-deps derivation into even more derivations, i.e. for each crate my project depends on. That means, we'd need to represent the entire dependency graph from cargo as graph of derivations.

Benefits would be (1) faster rebuilds while developing and (2) being able to share built crates between projects (e.g. if both projects are using the exact same version of a dependency), IIRC even cargo can't do that currently (though I'm not sure if that'll actually be possible).
Downsides are most likely (1) more expensive evaluations and (2) higher maintenance workload in this project because we may need to adapt on newer Cargo releases if certain internals change.

Do you think that'd be a reasonable thing to do? As I said, this is for now a hypothetical question because I need a reality check whether that's actually a good idea or completely stupid, haven't done a deep-dive into Cargo internals yet :D

Follow-up question: do you think it'd be possible to actually build all files in their own derivations in craneLib.buildPackage? That'd be the holy grail (for me at least :p) considering that we'd have completely incremental Rust builds with Nix then.

See for related work in Haskell e.g. https://github.com/matthewbauer/ghc-nix (I know that it's using a slightly different approach - i.e. "injecting" Nix builds into ghc, but the end-result is pretty similar to what I'd like to have).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions