Huge source repository, how to split up in smaller derivations

I’ve got a “toolsuite” to package with nixpkgs, and it is absolutely huge. The unpacked binary distribution is 8GiB in size.

I’ve been trying to write a derivation for the whole thing, but at a sluggish pace, because the first thing nix-build does is copy this huge chunk of source material into the Nix store, at least when I use src = unpacked-binary-distribution/., which I am doing for now to seemingly iterate faster. Maybe I’m wrong though and something else is slowing this down.

Ideally, I’d like to have almost no copying involved in developing this, and also have different derivations for the different tools involved in the package in the end. So somebody can say nix-build -A my-small-program or nix run my-repo#my-small-program and have a small download size in the end.

Is there good practice advice for such a thing?

lib.fileset & co. can help, though I’m not sure it helps if the source is part of a flake; after all the whole thing will need to be pulled into the nix store at some point.

For development you can probably copy it into a separate directory (so they don’t share a root) and just use it as a flake input (with flake = false); that way at least it doesn’t get re-copied for changes to your flake. You won’t be able to use lib.fileset to filter out a subset of a store path, though.

2 Likes