bazel_7: Filter bzlmod dependencies by name predicate

+26 -31
+11 -16
pkgs/development/tools/build-managers/bazel/bazel_7/bazel-repository-cache.nix
··· 4 , fetchurl 5 # The path to the right MODULE.bazel.lock 6 , lockfile 7 - # The path to a json file containing the list of hashes we should prefetch 8 - , requiredDeps ? null 9 - , extraInputs ? [ ] 10 }: 11 let 12 modules = builtins.fromJSON (builtins.readFile lockfile); ··· 28 in 29 # like foldl', force evaluation of intermediate results 30 builtins.seq acc' children; 31 32 extract_source = f: acc: value: 33 # We take any "attributes" object that has a "sha256" field. Every value ··· 72 && f attrs.name 73 then accWithNewSource else acc; 74 75 - # remove the "--" prefix, abusing undocumented negative substring length 76 - sanitize = builtins.substring 2 (-1); 77 - 78 - inputs = foldlJSON (extract_source (n: builtins.trace (sanitize n) true)) { } modules; 79 - 80 - requiredHashes = builtins.fromJSON (builtins.readFile requiredDeps); 81 - requiredAttrs = lib.genAttrs requiredHashes throw; 82 - 83 - requiredInputs = 84 - if requiredDeps == null 85 - then inputs 86 - else builtins.intersectAttrs requiredAttrs (builtins.trace inputs inputs); 87 88 command = '' 89 mkdir -p $out/content_addressable/sha256 ··· 92 # TODO: Do not re-hash. Use nix-hash to convert hashes 93 (drv: '' 94 filename=$(basename "${lib.head drv.urls}") 95 hash=$(${rnix-hashes}/bin/rnix-hashes --encoding BASE16 ${drv.sha256} | cut -f 2) 96 mkdir -p content_addressable/sha256/$hash 97 ln -sfn ${drv} content_addressable/sha256/$hash/file 98 # Expect file name conflicts 99 ln -sn ${drv} $filename || true 100 '') 101 - (builtins.attrValues requiredInputs ++ extraInputs) 102 ; 103 104 repository_cache = runCommand "bazel-repository-cache" { } command;
··· 4 , fetchurl 5 # The path to the right MODULE.bazel.lock 6 , lockfile 7 + # A predicate used to select only some dependencies based on their name 8 + , requiredDepNamePredicate ? _: true 9 + # Extra deps in the form of derivations producing a "single file" output path 10 + , extraDeps ? [ ] 11 }: 12 let 13 modules = builtins.fromJSON (builtins.readFile lockfile); ··· 29 in 30 # like foldl', force evaluation of intermediate results 31 builtins.seq acc' children; 32 + 33 + # remove the "--" prefix, abusing undocumented negative substring length 34 + sanitize = builtins.substring 2 (-1); 35 36 extract_source = f: acc: value: 37 # We take any "attributes" object that has a "sha256" field. Every value ··· 76 && f attrs.name 77 then accWithNewSource else acc; 78 79 + requiredSourcePredicate = n: requiredDepNamePredicate (sanitize n); 80 + requiredDeps = foldlJSON (extract_source requiredSourcePredicate) { } modules; 81 82 command = '' 83 mkdir -p $out/content_addressable/sha256 ··· 86 # TODO: Do not re-hash. Use nix-hash to convert hashes 87 (drv: '' 88 filename=$(basename "${lib.head drv.urls}") 89 + echo Bundling $filename 90 hash=$(${rnix-hashes}/bin/rnix-hashes --encoding BASE16 ${drv.sha256} | cut -f 2) 91 mkdir -p content_addressable/sha256/$hash 92 ln -sfn ${drv} content_addressable/sha256/$hash/file 93 # Expect file name conflicts 94 ln -sn ${drv} $filename || true 95 '') 96 + (builtins.attrValues requiredDeps ++ extraDeps) 97 ; 98 99 repository_cache = runCommand "bazel-repository-cache" { } command;
+15 -15
pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
··· 35 , gnupatch 36 , file 37 , installShellFiles 38 # updater 39 , python3 40 , writeScript ··· 75 distDir = repoCache; 76 repoCache = callPackage ./bazel-repository-cache.nix { 77 inherit lockfile; 78 - # TODO: efficiently filter so that all tests find their dependencies 79 - # without downloading 10 jdk versions 80 - # requiredDeps = ./required-hashes.json; 81 }; 82 83 defaultShellUtils = ··· 274 postPatch = 275 let 276 darwinPatches = '' 277 - 278 bazelLinkFlags () { 279 eval set -- "$NIX_LDFLAGS" 280 local flag ··· 367 -e 's!/bin/bash!${bash}/bin/bash!g' \ 368 -e 's!shasum -a 256!sha256sum!g' 369 370 - # Add compile options to command line. 371 # XXX: It would suit a bazelrc file better, but I found no way to pass it. 372 - # It seems it is always ignored. 373 # Passing EXTRA_BAZEL_ARGS is tricky due to quoting. 374 - 375 sedVerbose compile.sh \ 376 -e "/bazel_build /a\ --verbose_failures \\\\" \ 377 -e "/bazel_build /a\ --curses=no \\\\" \ 378 -e "/bazel_build /a\ --features=-layering_check \\\\" \ 379 -e "/bazel_build /a\ --experimental_strict_java_deps=off \\\\" \ 380 -e "/bazel_build /a\ --strict_proto_deps=off \\\\" \ 381 - -e "/bazel_build /a\ --action_env=NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE\" \\\\" \ 382 - -e "/bazel_build /a\ --action_env=NIX_LDFLAGS=\"$NIX_LDFLAGS\" \\\\" \ 383 - -e "/bazel_build /a\ --host_action_env=NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE\" \\\\" \ 384 - -e "/bazel_build /a\ --host_action_env=NIX_LDFLAGS=\"$NIX_LDFLAGS\" \\\\" \ 385 -e "/bazel_build /a\ --toolchain_resolution_debug='@bazel_tools//tools/jdk:(runtime_)?toolchain_type' \\\\" \ 386 -e "/bazel_build /a\ --tool_java_runtime_version=local_jdk \\\\" \ 387 -e "/bazel_build /a\ --java_runtime_version=local_jdk \\\\" \ 388 -e "/bazel_build /a\ --extra_toolchains=@bazel_tools//tools/jdk:all \\\\" \ 389 - -e "/bazel_build /a\ --distdir=${distDir} \\\\" \ 390 391 - #-e "/bazel_build /a\ --action_env=NIX_BINTOOLS=\"$NIX_BINTOOLS\" \\\\" \ 392 - #-e "/bazel_build /a\ --action_env=NIX_CC=\"$NIX_CC\" \\\\" \ 393 - #-e "/bazel_build /a\ --action_env=nativeBuildInputs=\"$nativeBuildInputs\" \\\\" \ 394 395 # Also build parser_deploy.jar with bootstrap bazel 396 # TODO: Turn into a proper patch
··· 35 , gnupatch 36 , file 37 , installShellFiles 38 + , lndir 39 # updater 40 , python3 41 , writeScript ··· 76 distDir = repoCache; 77 repoCache = callPackage ./bazel-repository-cache.nix { 78 inherit lockfile; 79 + # We use the release tarball that already has everything bundled, 80 + # But we need one extra dep required by our nonprebuilt java toolchains. 81 + requiredDepNamePredicate = name: 82 + null != builtins.match "rules_java~.*~toolchains~remote_java_tools" name; 83 }; 84 85 defaultShellUtils = ··· 276 postPatch = 277 let 278 darwinPatches = '' 279 bazelLinkFlags () { 280 eval set -- "$NIX_LDFLAGS" 281 local flag ··· 368 -e 's!/bin/bash!${bash}/bin/bash!g' \ 369 -e 's!shasum -a 256!sha256sum!g' 370 371 + # Augment bundled repository_cache with our extra paths 372 + ${lndir}/bin/lndir ${repoCache}/content_addressable \ 373 + $PWD/derived/repository_cache/content_addressable 374 + 375 + # Add required flags to bazel command line. 376 # XXX: It would suit a bazelrc file better, but I found no way to pass it. 377 + # It seems that bazel bootstrapping ignores it. 378 # Passing EXTRA_BAZEL_ARGS is tricky due to quoting. 379 sedVerbose compile.sh \ 380 -e "/bazel_build /a\ --verbose_failures \\\\" \ 381 -e "/bazel_build /a\ --curses=no \\\\" \ 382 -e "/bazel_build /a\ --features=-layering_check \\\\" \ 383 -e "/bazel_build /a\ --experimental_strict_java_deps=off \\\\" \ 384 -e "/bazel_build /a\ --strict_proto_deps=off \\\\" \ 385 -e "/bazel_build /a\ --toolchain_resolution_debug='@bazel_tools//tools/jdk:(runtime_)?toolchain_type' \\\\" \ 386 -e "/bazel_build /a\ --tool_java_runtime_version=local_jdk \\\\" \ 387 -e "/bazel_build /a\ --java_runtime_version=local_jdk \\\\" \ 388 -e "/bazel_build /a\ --extra_toolchains=@bazel_tools//tools/jdk:all \\\\" \ 389 390 + #-e "/bazel_build /a\ --action_env=NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE\" \\\\" \ 391 + #-e "/bazel_build /a\ --action_env=NIX_LDFLAGS=\"$NIX_LDFLAGS\" \\\\" \ 392 + #-e "/bazel_build /a\ --host_action_env=NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE\" \\\\" \ 393 + #-e "/bazel_build /a\ --host_action_env=NIX_LDFLAGS=\"$NIX_LDFLAGS\" \\\\" \ 394 395 # Also build parser_deploy.jar with bootstrap bazel 396 # TODO: Turn into a proper patch