tweag / rules_nixpkgs

Rules for importing Nixpkgs packages into Bazel.
Apache License 2.0
285 stars 80 forks source link

pkgsStatic.coreutils is no longer available on MacOS with recent nixpkgs #424

Open aherrmann opened 1 year ago

aherrmann commented 1 year ago

Describe the bug Updating the nixpkgs revision from https://github.com/NixOS/nixpkgs/commit/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b (NixOS 22.11) to https://github.com/NixOS/nixpkgs/commit/6500b4580c2a1f3d0f980d32d285739d8e156d92 (nixos-unstable at the time of writing) breaks the import of pkgsStatic.coreutils on MacOS 11 on x86_64, see this CI failure.

  error:
         … while calling the 'derivationStrict' builtin

           at /builtin/derivation.nix:9:12: (source not available)

         … while evaluating derivation 'coreutils-static-x86_64-apple-darwin-9.3'
           whose name attribute is located at /nix/store/i6hq63805y784dml4j8pgkrz3lryxzld-source/pkgs/stdenv/generic/make-derivation.nix:300:7
...
           at /nix/store/i6hq63805y784dml4j8pgkrz3lryxzld-source/pkgs/top-level/all-packages.nix:21811:69:

          21810|
          21811|   libcCross = assert stdenv.targetPlatform != stdenv.buildPlatform; libcCrossChooser stdenv.targetPlatform.libc;
               |                                                                     ^
          21812|

         … while calling 'libcCrossChooser'

           at /nix/store/i6hq63805y784dml4j8pgkrz3lryxzld-source/pkgs/top-level/all-packages.nix:21785:22:

          21784|   # We can choose:
          21785|   libcCrossChooser = name:
               |                      ^
          21786|     # libc is hackily often used from the previous stage. This `or`

         error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin`
  INFO: Repository coreutils_static instantiated at:
    /Users/runner/work/rules_nixpkgs/rules_nixpkgs/WORKSPACE:45:16: in <toplevel>
    /private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/rules_nixpkgs_core/nixpkgs.bzl:723:21: in nixpkgs_package
  Repository rule _nixpkgs_package defined at:
    /private/var/tmp/_bazel_runner/a4a3182e50c9460fa52b8c6c1e6f916f/external/rules_nixpkgs_core/nixpkgs.bzl:591:35: in <toplevel>
  ERROR: An error occurred during the fetch of repository '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"
      Return code: 1
...

The same tests succeed on an arm64 MacOS machine.

To Reproduce Update the nixpkgs revision used in the rules_nixpkgs tests as described above and run the tests in the top-level WORKSPACE on MacOS 11 x86_64.

Expected behavior The tests should pass on MacOS x86_64 with pkgsStatic.coreutils as they did before the nixpkgs update. This may very well be an upstream nixpkgs issue. However, at this point I don't have enough information to raise a meaningful issue on nixpkgs itself. So, I'm opening this issue first.

Environment

Additional context This issue surfaced in the context of https://github.com/tweag/rules_nixpkgs/pull/423 and can be worked around by not using pkgsStatic on MacOS.

avdv commented 10 months ago

Opened an upstream issue: https://github.com/NixOS/nixpkgs/issues/270375

This seems to be caused by this PR https://github.com/NixOS/nixpkgs/pull/235990 which is (somewhat ironically) titled "nixStatic: Fix darwin".

The bottom line is that before that change coreutils and pkgsStatic.coreutils were exactly the same on Darwin:

$ nix-shell -I nixpkgs=./. --pure -p which pkgsStatic.coreutils --run 'which tsort'
/nix/store/3acj5l3cwmliiihig0hm6y4p0nsk8jgi-coreutils-9.1/bin/tsort
$ nix-shell -I nixpkgs=./. --pure -p which coreutils --run 'which tsort'
/nix/store/3acj5l3cwmliiihig0hm6y4p0nsk8jgi-coreutils-9.1/bin/tsort