nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 updateAutotoolsGnuConfigScriptsHook,
5 glibcLocales,
6 fetchurl,
7 pcre2,
8 libiconv,
9 perl,
10 runtimeShellPackage,
11}:
12
13# Note: this package is used for bootstrapping fetchurl, and thus
14# cannot use fetchpatch! All mutable patches (generated by GitHub or
15# cgit) that are needed here should be included directly in Nixpkgs as
16# files.
17
18let
19 version = "3.12";
20in
21
22stdenv.mkDerivation {
23 pname = "gnugrep";
24 inherit version;
25
26 src = fetchurl {
27 url = "mirror://gnu/grep/grep-${version}.tar.xz";
28 hash = "sha256-JkmyfA6Q5jLq3NdXvgbG6aT0jZQd5R58D4P/dkCKB7k=";
29 };
30
31 patches = [
32 # Fixes test-float-h failure on ppc64 with C23
33 # https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00021.html
34 # Multiple upstream commits squashed with adjustments, see header
35 ./gnulib-float-h-tests-port-to-C23-PowerPC-GCC.patch
36 ];
37
38 # Some gnulib tests fail
39 # - on Musl: https://github.com/NixOS/nixpkgs/pull/228714
40 # - on x86_64-darwin: https://github.com/NixOS/nixpkgs/pull/228714#issuecomment-1576826330
41 # - when building on Darwin (cross-compilation): test-nl_langinfo-mt fails
42 postPatch =
43 if stdenv.hostPlatform.isMusl || stdenv.buildPlatform.isDarwin then
44 ''
45 sed -i 's:gnulib-tests::g' Makefile.in
46 ''
47 else
48 null;
49
50 nativeCheckInputs = [
51 perl
52 glibcLocales
53 ];
54 outputs = [
55 "out"
56 "info"
57 ]; # the man pages are rather small
58
59 nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ];
60 buildInputs = [
61 pcre2
62 libiconv
63 ]
64 ++ lib.optional (!stdenv.hostPlatform.isWindows) runtimeShellPackage;
65
66 # cygwin: FAIL: multibyte-white-space
67 # freebsd: FAIL mb-non-UTF8-performance
68 # x86_64-darwin: fails 'stack-overflow' tests on Rosetta 2 emulator
69 # aarch32: fails 'stack-overflow' when run on qemu under x86_64
70 doCheck =
71 !stdenv.hostPlatform.isCygwin
72 && !stdenv.hostPlatform.isFreeBSD
73 && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64)
74 && !stdenv.buildPlatform.isRiscV64
75 && !stdenv.hostPlatform.isAarch32;
76
77 # On macOS, force use of mkdir -p, since Grep's fallback
78 # (./install-sh) is broken.
79 preConfigure = ''
80 export MKDIR_P="mkdir -p"
81 '';
82
83 enableParallelBuilding = true;
84
85 # Fix reference to sh in bootstrap-tools, and invoke grep via
86 # absolute path rather than looking at argv[0].
87 postInstall = ''
88 rm $out/bin/egrep $out/bin/fgrep
89 echo "#! /bin/sh" > $out/bin/egrep
90 echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
91 echo "#! /bin/sh" > $out/bin/fgrep
92 echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
93 chmod +x $out/bin/egrep $out/bin/fgrep
94 '';
95
96 env = lib.optionalAttrs (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) {
97 NIX_CFLAGS_COMPILE = "-Wno-error=format-security";
98 };
99
100 meta = {
101 homepage = "https://www.gnu.org/software/grep/";
102 description = "GNU implementation of the Unix grep command";
103
104 longDescription = ''
105 The grep command searches one or more input files for lines
106 containing a match to a specified pattern. By default, grep
107 prints the matching lines.
108 '';
109
110 license = lib.licenses.gpl3Plus;
111
112 maintainers = [
113 lib.maintainers.das_j
114 lib.maintainers.m00wl
115 ];
116 teams = [ lib.teams.security-review ];
117 platforms = lib.platforms.all;
118 mainProgram = "grep";
119 identifiers.cpeParts = lib.meta.cpeFullVersionWithVendor "gnu" version // {
120 product = "grep";
121 };
122 };
123
124 passthru = {
125 inherit pcre2;
126 };
127}