-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify rules_nixpkgs_core module extensions #423
Conversation
This uses the new isolated module extensions feature [1], instead of a hub-repository approach [2] [3], to distinguish globally unified repositories and locally specialized repositories. [1]: bazelbuild/bazel#18529 [2]: bazelbuild/bazel#17048 [3]: bazelbuild/bazel#17493
Otherwise the tests only cover the cases of rules_nixpkgs_core or the root module.
Except those that require further simple repository tags to be implemented first.
After removing the old extensions we can now use the shorter names "repository" and "package".
This is so that modules can define overrides as dev-depencies.
This is to test logic that differs between an intermediate module or the root module or rules_nixpkgs_core.
Version 2.7, 2.8, and 2.9 were removed.
The CI failure seems to be caused by NixOS/nixpkgs#258607. I've opened NixOS/nixpkgs#258608 with a fix. And pushed a workaround until the fix is available in nixpkgs. |
The corresponding files no longer exist and the import was no longer in effect since the @nixpkgs import in docs_dependencies_2 took precedence.
To prevent the following build error on MacOS x86_64 ``` > error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin` ERROR: /Users/runner/work/rules_nixpkgs/rules_nixpkgs/WORKSPACE:45:16: fetching _nixpkgs_package rule //external:coreutils_static: Traceback (most recent call last): File "/private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/rules_nixpkgs_core/nixpkgs.bzl", line 589, column 31, in _nixpkgs_package_impl _nixpkgs_build_and_symlink(repository_ctx, [nix_build_path], expr_args, build_file_content) File "/private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/rules_nixpkgs_core/nixpkgs.bzl", line 447, column 34, in _nixpkgs_build_and_symlink exec_result = execute_or_fail( File "/private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/rules_nixpkgs_core/util.bzl", line 97, column 13, in execute_or_fail fail(""" Error in fail: Cannot build Nix derivation for package '@coreutils_static'. Command: "/nix/store/x5wfa3afc4l2rc7zx3wiiwcm5j3j4lbc-nix-2.17.0/bin/nix-build" "-I" "nixpkgs=/private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/nixpkgs/nixpkgs" "-E" "import <nixpkgs> { config = {}; overlays = []; }" "-A" "pkgsStatic.coreutils" "--out-link" "bazel-support/nix-out-link" ``` https://github.com/tweag/rules_nixpkgs/actions/runs/6390957120/job/17345262106?pr=423#step:6:846 Error message origin in nixpkgs: https://github.com/aherrmann/nixpkgs/blob/59998678277cf465e749a144cf707021285bdf82/pkgs/top-level/all-packages.nix#L21799-L21802
fa796bf
to
651fe0d
Compare
The second CI failure seems to be caused by an incompatibility with more recent nixpkgs revisions and MacOS 11 on x86_64. I have not been able to track down the exact reason, but worked around the issue by falling back to |
CI is green now, so this is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting changeset. Overall not much changed in the interface, except for some simplifications, so this is a much welcome change.
I would love to see the implications for more complex use cases of rules_nixpkgs, where @nixpkgs is not a vanilla upstream nixpkgs, but I think there is kind of a global assumption that @nixpkgs is some version of upstream nixpkgs.
I am still annoyed that bzlmod (at least for rules_nixpkgs) relies on so many conventions and unchecked assumptions, but there is not much we can do about that.
Some comments I left are merely notes for me to check after the review, these are marked with XXX.
@@ -1,6 +1,6 @@ | |||
{ | |||
inputs = { | |||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; | |||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason for this change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to get access to Bazel version 6.3.2, which is not yet available in NixOS-22.11.
@@ -8,7 +8,7 @@ sh_test( | |||
"//nixpkgs:srcs", | |||
"//tests/invalid_nixpkgs_package:srcs", | |||
"@coreutils_static//:bin", | |||
"@nix_2_7//:bin", | |||
"@nix_2_10//:bin", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for thins change, except general maintenance ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, version 2.7 (and 2.8 and 2.9) are no longer available in the more recent nixpkgs revision (unstable). So we need to bump the version.
Co-authored-by: Guillaume Maudoux <[email protected]>
Part of #183.
The previous implementation of the rules_nixpkgs_core module extensions (#344, #363, #369, #364) used a hub-repository to manage Nix repository and package import scope.
Since then, Bazel (>= 6.3) has introduced isolated module extension instances and automatic generation of
use_repo
stanzas. Both these features solve the same problems that the hub-repository implementation addressed, see below.This PR replaces the previous hub-repository based implementation by a simpler implementation based on these new Bazel features. A clear advantage is that this means that users can use plain Bazel labels to refer to imported repositories and packages instead of having to access them through hub-repository accessors. This should also be an advantage in terms of WORKSPACE to bzlmod migration effort.
How isolated extensions and automatically generated
use_repo
address rules_nixpkgs's requirements:use_repo
stanzas, it is very easy for a user to manage the imports.