Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at fix-function-merge 110 lines 3.7 kB view raw
1{ buildBazelPackage 2, bazel_5 3, fetchFromGitHub 4, git 5, go_1_21 6, python3 7, lib, stdenv 8}: 9 10let 11 patches = [ 12 ./use-go-in-path.patch 13 ]; 14 15 # Patch the protoc alias so that it always builds from source. 16 rulesProto = fetchFromGitHub { 17 owner = "bazelbuild"; 18 repo = "rules_proto"; 19 rev = "4.0.0"; 20 hash = "sha256-WVPZx14thneAC4PdiDhBibnPwlCKEF9c93CHR0t1Efo="; 21 postFetch = '' 22 sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release 23 cat <<EOF >>$out/proto/private/BUILD.release 24 alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"]) 25 EOF 26 ''; 27 }; 28 29in 30buildBazelPackage rec { 31 pname = "bazel-watcher"; 32 version = "0.25.2"; 33 34 src = fetchFromGitHub { 35 owner = "bazelbuild"; 36 repo = "bazel-watcher"; 37 rev = "v${version}"; 38 hash = "sha256-lreGKA0DZiOd1bJq8NNQ+80cyDwiughoXCkKu1RaZmc="; 39 }; 40 41 nativeBuildInputs = [ go_1_21 git python3 ]; 42 removeRulesCC = false; 43 44 bazel = bazel_5; 45 bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ]; 46 bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ]; 47 bazelTargets = [ "//cmd/ibazel" ]; 48 49 fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system 50 fetchAttrs = { 51 inherit patches; 52 53 preBuild = '' 54 patchShebangs . 55 56 echo ${bazel_5.version} > .bazelversion 57 ''; 58 59 preInstall = '' 60 # Remove the go_sdk (it's just a copy of the go derivation) and all 61 # references to it from the marker files. Bazel does not need to download 62 # this sdk because we have patched the WORKSPACE file to point to the one 63 # currently present in PATH. Without removing the go_sdk from the marker 64 # file, the hash of it will change anytime the Go derivation changes and 65 # that would lead to impurities in the marker files which would result in 66 # a different hash for the fetch phase. 67 rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker} 68 sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker 69 70 # Retains go build input markers 71 chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} 72 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} 73 74 # Remove the gazelle tools, they contain go binaries that are built 75 # non-deterministically. As long as the gazelle version matches the tools 76 # should be equivalent. 77 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker} 78 sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker 79 80 # remove com_google_protobuf because it had files with different permissions on linux and darwin 81 rm -rf $bazelOut/external/com_google_protobuf 82 ''; 83 84 sha256 = "sha256-B2KVD/FmkAa7MNhLaH286gF3uA20qjN3CoA83KRB9E8="; 85 }; 86 87 buildAttrs = { 88 inherit patches; 89 90 preBuild = '' 91 patchShebangs . 92 93 substituteInPlace cmd/ibazel/BUILD.bazel --replace '{STABLE_GIT_VERSION}' ${version} 94 echo ${bazel_5.version} > .bazelversion 95 ''; 96 97 installPhase = '' 98 install -Dm755 bazel-bin/cmd/ibazel/ibazel_/ibazel $out/bin/ibazel 99 ''; 100 }; 101 102 meta = with lib; { 103 homepage = "https://github.com/bazelbuild/bazel-watcher"; 104 description = "Tools for building Bazel targets when source files change"; 105 license = licenses.asl20; 106 maintainers = with maintainers; [ kalbasit ]; 107 mainProgram = "ibazel"; 108 platforms = platforms.all; 109 }; 110}