rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Variation of #214 (Rule to generate docker images with nix store paths)

Open dmadisetti opened this issue 2 years ago • 9 comments

Reduced change set of #214, with motivation of getting some momentum behind this.

Notable changes, utilizing the bazel-support directory to store default.nix and BUILD files so the docker definition can hook in.

TODO:

  • [ ] Tests
  • [ ] Documentation
  • [ ] Allow for build artifacts to be bundled

Ideally, I'm going to use this as starting point so I can get singularity image builds more seamlessly in my workflow as an approach to #291

dmadisetti avatar Mar 15 '23 12:03 dmadisetti

@jcpetruzza @aherrmann

dmadisetti avatar Mar 15 '23 12:03 dmadisetti

Looks like the CI errors are due to the tilde in path issue that @aherrmann encountered a little while ago.

benradf avatar Mar 16 '23 12:03 benradf

Oh interesting. Is this the work around? https://github.com/NixOS/nix/issues/7742#issuecomment-1420407931

I'll take a stab at this later today

dmadisetti avatar Mar 16 '23 14:03 dmadisetti

Oh interesting. Is this the work around? NixOS/nix#7742 (comment)

I'll take a stab at this later today

Yeah, I think that should do the trick. From the documentation for nixpkgs_package:

Note, labels to external workspaces will resolve to paths that contain ~ characters if the Bazel flag --enable_bzlmod is true. Nix does not support ~ characters in path literals at the time of writing, see #7742. Meaning, the result of location expansion may not form a valid Nix path literal. Use ./$${"$(location @for//:example)"} to work around this limitation if you need to pass a path argument via --arg, or pass the resulting path as a string value using --argstr and combine it with an additional --arg workspace_root ./. argument using workspace_root + ("/" + path_str).

benradf avatar Mar 16 '23 14:03 benradf

Sorry for the failure spam. I was unable to replicate this locally + found additional failure cases I wasn't seeing locally.

If this doesn't work, I will revisit later

dmadisetti avatar Apr 04 '23 03:04 dmadisetti

Yeah. No idea. Running bazel test tests:all from testing/core passes locally, and I have no weird _main~non_module_deps~hello external dep (tried bazel_5 and bazel_6). Also seems to work executing .github/build-and-test. I guess I don't really understand how these special paths are arising?

dmadisetti avatar Apr 04 '23 03:04 dmadisetti

I guess I don't really understand how these special paths are arising?

They should arise when you enable bzlmod either by bazel test --config=bzlmod in testing/core, or with export BZLMOD_ENABLED=true when running .github/build-and-test.

aherrmann avatar Apr 05 '23 08:04 aherrmann

I'd like to try and get this merged. Unfortunately this commit that refactored _nixpkgs_package_impl has caused a non-trivial merge conflict. I'll have a go at resolving it when I have some time though.

benradf avatar Sep 07 '23 08:09 benradf

I've been using an extension of this that packages build artifacts: https://github.com/cemel-jhu/rules_nixpkgs/pull/1/files

dmadisetti avatar Nov 15 '23 06:11 dmadisetti