lol
1{ lib, stdenv, glibcLocales, fetchurl, pcre2, libiconv, perl }:
2
3# Note: this package is used for bootstrapping fetchurl, and thus
4# cannot use fetchpatch! All mutable patches (generated by GitHub or
5# cgit) that are needed here should be included directly in Nixpkgs as
6# files.
7
8let version = "3.11"; in
9
10stdenv.mkDerivation {
11 pname = "gnugrep";
12 inherit version;
13
14 src = fetchurl {
15 url = "mirror://gnu/grep/grep-${version}.tar.xz";
16 hash = "sha256-HbKu3eidDepCsW2VKPiUyNFdrk4ZC1muzHj1qVEnbqs=";
17 };
18
19 # Some gnulib tests fail
20 # - on Musl: https://github.com/NixOS/nixpkgs/pull/228714
21 # - on x86_64-darwin: https://github.com/NixOS/nixpkgs/pull/228714#issuecomment-1576826330
22 postPatch = if stdenv.hostPlatform.isMusl || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) then ''
23 sed -i 's:gnulib-tests::g' Makefile.in
24 '' else null;
25
26 nativeCheckInputs = [ perl glibcLocales ];
27 outputs = [ "out" "info" ]; # the man pages are rather small
28
29 buildInputs = [ pcre2 libiconv ];
30
31 # cygwin: FAIL: multibyte-white-space
32 # freebsd: FAIL mb-non-UTF8-performance
33 # x86_64-darwin: fails 'stack-overflow' tests on Rosetta 2 emulator
34 doCheck = !stdenv.isCygwin && !stdenv.isFreeBSD && !(stdenv.isDarwin && stdenv.hostPlatform.isx86_64);
35
36 # On macOS, force use of mkdir -p, since Grep's fallback
37 # (./install-sh) is broken.
38 preConfigure = ''
39 export MKDIR_P="mkdir -p"
40 '';
41
42 enableParallelBuilding = true;
43
44 # Fix reference to sh in bootstrap-tools, and invoke grep via
45 # absolute path rather than looking at argv[0].
46 postInstall =
47 ''
48 rm $out/bin/egrep $out/bin/fgrep
49 echo "#! /bin/sh" > $out/bin/egrep
50 echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
51 echo "#! /bin/sh" > $out/bin/fgrep
52 echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
53 chmod +x $out/bin/egrep $out/bin/fgrep
54 '';
55
56 meta = with lib; {
57 homepage = "https://www.gnu.org/software/grep/";
58 description = "GNU implementation of the Unix grep command";
59
60 longDescription = ''
61 The grep command searches one or more input files for lines
62 containing a match to a specified pattern. By default, grep
63 prints the matching lines.
64 '';
65
66 license = licenses.gpl3Plus;
67
68 maintainers = [
69 maintainers.das_j
70 maintainers.m00wl
71 ];
72 platforms = platforms.all;
73 mainProgram = "grep";
74 };
75
76 passthru = {
77 inherit pcre2;
78 };
79}