rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Make a platform switch to assume packages are already built

Open aspiwack opened this issue 6 years ago • 3 comments

Currently, when getting packages with rules_nixpkgs, bazel will call nix to build said dependencies.

It doesn't work well, however, when making a nix derivation to package our bazel-built software.

There, we expect that the nix derivation will describe all of the dependencies for the package, and that they will be built by the time bazel starts running.

Here is a thought: we may make a toolchain which, instead of building the dependencies, assume that they are built already. And make it so that a platform argument switches between the two modes. So that a build, driven from nix, will simply pass a command line argument, and won't try to build the dependencies anymore. While building the project, for a developer, will still be only a matter of bazel build.

Now, I'm not sure it is a good idea, for one thing, it requires that the version of nixpkgs used by the Bazel build is the same as the version of nixpkgs assumed by Bazel. Would it even work to package Bazel project within nixpkgs?

What does everybody think?

aspiwack avatar Aug 07 '19 10:08 aspiwack

I think this problem goes away if we have recursive Nix. cc @edolstra @adisbladis

If Nix was happy to be called recursively, we wouldn't need any toolchain, which in any case is not possible, because rules_nixpkgs is a set of repository rules and toolchains are not available in repository rules.

mboes avatar Aug 07 '19 12:08 mboes

This is probably true. And it may be better for isolation, as it would allow packages to depend on another version of nixpkgs.

On the other hand, this could be considered a kind of a leak too. So we may not like it.

I don't know how far away recursive nix is, though.

aspiwack avatar Aug 07 '19 12:08 aspiwack

An alternative approach that could be utilized in something like buildBazelPackage is to make the required Nix packages a dependency on the Nix level and pass them in using --override_repository.

aherrmann avatar Feb 08 '22 11:02 aherrmann