Skip to content

Commit 83abb9e

Browse files
authored
livegrep: init at 0-unstable-2026-01-06 (#510423)
2 parents 88b39cd + 128e9f5 commit 83abb9e

4 files changed

Lines changed: 244 additions & 0 deletions

File tree

maintainers/maintainer-list.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19480,6 +19480,14 @@
1948019480
name = "Nicolas Goudry";
1948119481
keys = [ { fingerprint = "21B6 A59A 4E89 0B1B 83E3 0CDB 01C8 8C03 5450 9AA9"; } ];
1948219482
};
19483+
nicolas-guichard = {
19484+
name = "Nicolas Qiu Guichard";
19485+
email = "nicolas@guichard.eu";
19486+
matrix = "@nicolas:guichard.eu";
19487+
github = "nicolas-guichard";
19488+
githubId = 11260285;
19489+
keys = [ { fingerprint = "22B2 237B 0158 EE61 704C E191 7684 D229 0313 47AA"; } ];
19490+
};
1948319491
nicomem = {
1948419492
email = "nix@nicomem.com";
1948519493
github = "nicomem";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Subject: [PATCH] Use patched rules_js and Nix-provided nodejs
2+
3+
By default aspect_rules_js brings a precompiled nodejs which uses a
4+
non-nixpkgs dynamic linker. Instead use nodejs from nixpkgs. This
5+
requires a patched rules_js as specifying npm_path fails otherwise
6+
(see the rules_js patch).
7+
8+
We also require a patched rules_js because it otherwise generates and
9+
immediately executes scripts with `#!/usr/bin/env bash`.
10+
11+
---
12+
MODULE.bazel | 4 ++++
13+
nixpkgs-toolchains/BUILD.bazel | 13 +++++++++++++
14+
2 files changed, 17 insertions(+)
15+
create mode 100644 nixpkgs-toolchains/BUILD.bazel
16+
17+
diff --git a/MODULE.bazel b/MODULE.bazel
18+
index 4df2a500..b7525996 100644
19+
--- a/MODULE.bazel
20+
+++ b/MODULE.bazel
21+
@@ -35,6 +35,10 @@ use_repo(
22+
)
23+
24+
bazel_dep(name = "aspect_rules_js", version = "2.4.0")
25+
+local_path_override(module_name = "aspect_rules_js", path = "@rules_js@")
26+
+
27+
+bazel_dep(name = "rules_nodejs", version = "6.3.0")
28+
+register_toolchains("//nixpkgs-toolchains:nixpkgs_nodejs_toolchain")
29+
30+
npm = use_extension(
31+
"@aspect_rules_js//npm:extensions.bzl",
32+
diff --git a/nixpkgs-toolchains/BUILD.bazel b/nixpkgs-toolchains/BUILD.bazel
33+
new file mode 100644
34+
index 00000000..3b8a7940
35+
--- /dev/null
36+
+++ b/nixpkgs-toolchains/BUILD.bazel
37+
@@ -0,0 +1,13 @@
38+
+load("@rules_nodejs//nodejs:toolchain.bzl", "nodejs_toolchain")
39+
+
40+
+nodejs_toolchain(
41+
+ name = "node_toolchain",
42+
+ node_path = "@nodejs@/bin/node",
43+
+ npm_path = "@nodejs@/bin/npm",
44+
+)
45+
+
46+
+toolchain(
47+
+ name = "nixpkgs_nodejs_toolchain",
48+
+ toolchain = ":node_toolchain",
49+
+ toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
50+
+)
51+
--
52+
2.53.0
53+
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Subject: [PATCH] Fix for toolchain with npm_path
2+
3+
When specifying a toolchain with a npm_path, transitive_launcher_files
4+
is None which leads to an error here.
5+
6+
Instead, don't set transitive_files at all.
7+
8+
---
9+
js/private/js_binary.bzl | 1 -
10+
1 file changed, 1 deletion(-)
11+
12+
diff --git a/js/private/js_binary.bzl b/js/private/js_binary.bzl
13+
index 37627809..29e3bf62 100644
14+
--- a/js/private/js_binary.bzl
15+
+++ b/js/private/js_binary.bzl
16+
@@ -555,7 +555,6 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
17+
include_npm_sources = ctx.attr.include_npm_sources,
18+
).merge(ctx.runfiles(
19+
files = launcher_files,
20+
- transitive_files = transitive_launcher_files,
21+
))
22+
23+
return struct(
24+
--
25+
2.53.0
26+

0 commit comments

Comments
 (0)