Lazy Programs: only build a program once called

I am wondering if there is an existing nix tool that allows building of “lazy” packages.
Essentially, this wraps any package with a wrapper script. Once something calls the binary the wrapper script then starts actually building whatever was wrapped and transparently runs the actual binary with the given arguments.

I imagine for programs that are not used as often, this would allow for quicker build times.

1 Like

Yes, I’ve built exactly that some time ago:

1 Like

Ah nice :slight_smile:

From the examples the usage seems to be a bit more involved than packages.something_lazy = lib.lazy-drv.lazy-run pkgs.gcc. I’m particularly confused as to what the source argument should receive?

Lets say I want to have a lazy gcc, from nixpkgs. How would that look like?

The readme explains this:

Path to the Nix file declaring the derivation to realise. If the expression in the file is a function, it must take an attribute set where all values have defaults.

I don’t think that makes sense, because gcc would already be built?

1 Like

You can have gcc get realized only when you run it from the shell environment, just replace example-command with pkgs.gcc. But you won’t have all the other executables, because lazy-run only picks the one in meta.mainProgram. You’d need to iterate over all executables known at evaluation time (and put them into attrs) to get all of them into a shell environment lazily.