|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + buildBazelPackage, |
| 6 | + bazel_7, |
| 7 | + nix-update-script, |
| 8 | + applyPatches, |
| 9 | + nodejs, |
| 10 | + cctools, |
| 11 | +}: |
| 12 | +let |
| 13 | + cc_tools = [ |
| 14 | + "codesearch" |
| 15 | + "analyze-re" |
| 16 | + "dump-file" |
| 17 | + "inspect-index" |
| 18 | + ]; |
| 19 | + |
| 20 | + go_tools = [ |
| 21 | + "livegrep" |
| 22 | + "lg" |
| 23 | + "livegrep-fetch-reindex" |
| 24 | + "livegrep-github-reindex" |
| 25 | + "livegrep-reload" |
| 26 | + ]; |
| 27 | + |
| 28 | + registry = fetchFromGitHub { |
| 29 | + owner = "bazelbuild"; |
| 30 | + repo = "bazel-central-registry"; |
| 31 | + rev = "0f256a72067e42d62bb568cc2619f98deed139e2"; |
| 32 | + hash = "sha256-OcMLg0KiAQOJZLH8r+QkeQ9bxcEc4L0dCgyUv5PkLQk="; |
| 33 | + }; |
| 34 | + |
| 35 | + rules_js = applyPatches { |
| 36 | + src = fetchFromGitHub { |
| 37 | + owner = "aspect-build"; |
| 38 | + repo = "rules_js"; |
| 39 | + rev = "v2.4.0"; |
| 40 | + hash = "sha256-Z0Oq5FQ26KS+tLwawXs2Jgox0Cau4E76IwzNKyTK0Tk="; |
| 41 | + }; |
| 42 | + |
| 43 | + patches = [ |
| 44 | + ./rule-js-Fix-toolchain-with-npm_path.patch |
| 45 | + ]; |
| 46 | + |
| 47 | + postPatch = '' |
| 48 | + patchShebangs --build \ |
| 49 | + npm/private/lifecycle/bundle.sh \ |
| 50 | + npm/private/lifecycle/min/node-gyp-bin/node-gyp \ |
| 51 | + npm/private/noop.sh \ |
| 52 | + npm/private/versions_mirror.sh \ |
| 53 | + js/private/node_wrapper.sh \ |
| 54 | + js/private/npm_wrapper.sh |
| 55 | +
|
| 56 | + substituteInPlace \ |
| 57 | + npm/private/utils.bzl \ |
| 58 | + npm/private/lifecycle/lifecycle-hooks.js \ |
| 59 | + npm/private/lifecycle/min/index.min.js \ |
| 60 | + js/private/js_binary.sh.tpl \ |
| 61 | + --replace-fail '#!/usr/bin/env bash' "#!$(type -p bash)" |
| 62 | + ''; |
| 63 | + }; |
| 64 | + |
| 65 | + bazelDepsHashByBuildAndHost = { |
| 66 | + x86_64-linux.x86_64-linux = "sha256-PastkoOioWqlmGFHZiZ2S1ahWZu1UBhqHIfD2M/ff6A="; |
| 67 | + aarch64-linux.aarch64-linux = "sha256-mNWnpmk/dNQYKnP3YbfK5ott0+41I+49aH6RhWEMOGM="; |
| 68 | + }; |
| 69 | + bazelDepsHashByHost = bazelDepsHashByBuildAndHost.${stdenv.buildPlatform.system} or { }; |
| 70 | + bazelDepsHash = bazelDepsHashByHost.${stdenv.hostPlatform.system} or ""; |
| 71 | +in |
| 72 | +buildBazelPackage { |
| 73 | + pname = "livegrep"; |
| 74 | + version = "2026-02-10"; |
| 75 | + |
| 76 | + src = fetchFromGitHub { |
| 77 | + owner = "livegrep"; |
| 78 | + repo = "livegrep"; |
| 79 | + rev = "923d5ad71dfe60900e6c2017b2fa4a5ff902ad71"; |
| 80 | + hash = "sha256-SYbJJuUX13otaGRsYLTp6XWU3BBNmtNIpUxyu11U+b0="; |
| 81 | + }; |
| 82 | + |
| 83 | + patches = [ |
| 84 | + ./livegrep-Use-patched-rules_js-and-nodejs-from-nixpkgs.patch |
| 85 | + ]; |
| 86 | + |
| 87 | + postPatch = '' |
| 88 | + substituteInPlace nixpkgs-toolchains/BUILD.bazel --subst-var-by nodejs "${nodejs}" |
| 89 | + substituteInPlace MODULE.bazel --subst-var-by rules_js "${rules_js}" |
| 90 | + ''; |
| 91 | + |
| 92 | + bazelFlags = [ |
| 93 | + "--registry" |
| 94 | + "file://${registry}" |
| 95 | + ]; |
| 96 | + |
| 97 | + env = lib.optionalAttrs stdenv.hostPlatform.isDarwin { |
| 98 | + LIBTOOL = "${cctools}/bin/libtool"; |
| 99 | + }; |
| 100 | + |
| 101 | + fetchAttrs = { |
| 102 | + preInstall = '' |
| 103 | + # Avoid bash and $out store paths leaking into the fixed-output derivation |
| 104 | + rm $bazelOut/external/aspect_rules_js~~npm~npm/_exists.sh |
| 105 | + rm -r $bazelOut/external/rules_shell~~sh_configure~local_config_shell |
| 106 | +
|
| 107 | + # Remove some non-reproducible and unused files |
| 108 | + rm -r $bazelOut/external/gazelle~~non_module_deps~bazel_gazelle_go_repository_cache |
| 109 | + rm -r $bazelOut/external/gazelle~~non_module_deps~bazel_gazelle_go_repository_tools |
| 110 | + ''; |
| 111 | + |
| 112 | + hash = bazelDepsHash; |
| 113 | + }; |
| 114 | + |
| 115 | + bazel = bazel_7; |
| 116 | + |
| 117 | + bazelBuildFlags = [ "-c opt" ]; |
| 118 | + bazelTargets = |
| 119 | + (builtins.map (tool: "//src/tools:${tool}") cc_tools) |
| 120 | + ++ (builtins.map (tool: "//cmd/${tool}") go_tools); |
| 121 | + |
| 122 | + buildAttrs = { |
| 123 | + installPhase = '' |
| 124 | + pushd "bazel-bin/src/tools" |
| 125 | + install -Dt "$out/bin" ${builtins.toString cc_tools} |
| 126 | + popd |
| 127 | +
|
| 128 | + for go_tool in ${builtins.toString go_tools}; do |
| 129 | + install -D -t "$out/bin" "bazel-bin/cmd/$go_tool/''${go_tool}_/$go_tool" |
| 130 | + done |
| 131 | +
|
| 132 | + mkdir -p "$out/bin/livegrep.runfiles/com_github_livegrep_livegrep" |
| 133 | + cp -Lr "bazel-bin/cmd/livegrep/livegrep_/livegrep.runfiles/_main/web" "$out/bin/livegrep.runfiles/com_github_livegrep_livegrep" |
| 134 | + ''; |
| 135 | + }; |
| 136 | + |
| 137 | + passthru = { |
| 138 | + inherit rules_js; |
| 139 | + updateScript = nix-update-script { }; |
| 140 | + }; |
| 141 | + |
| 142 | + strictDeps = true; |
| 143 | + __structuredAttrs = true; |
| 144 | + |
| 145 | + meta = { |
| 146 | + description = "Livegrep is a tool, partially inspired by Google Code Search, for interactive regex search of ~gigabyte-scale source repositories."; |
| 147 | + homepage = "http://livegrep.com/"; |
| 148 | + downloadPage = "https://github.com/livegrep/livegrep"; |
| 149 | + license = lib.licenses.bsd2; |
| 150 | + maintainers = with lib.maintainers; [ nicolas-guichard ]; |
| 151 | + mainProgram = "livegrep"; |
| 152 | + badPlatforms = [ |
| 153 | + # Error in fail: Unable to find a CC toolchain using toolchain resolution |
| 154 | + lib.systems.inspect.patterns.isDarwin |
| 155 | + ]; |
| 156 | + }; |
| 157 | +} |
0 commit comments