lol
1{ lib
2, stdenv
3, fetchpatch
4, fetchFromGitHub
5, autoreconfHook
6, onigurumaSupport ? true
7, oniguruma
8}:
9
10stdenv.mkDerivation rec {
11 pname = "jq";
12 version = "1.6";
13
14 src = fetchFromGitHub {
15 owner = "stedolan";
16 repo = "jq";
17 rev = "${pname}-${version}";
18 hash = "sha256-CIE8vumQPGK+TFAncmpBijANpFALLTadOvkob0gVzro";
19 };
20
21 patches = [
22 (fetchpatch {
23 name = "fix-tests-when-building-without-regex-supports.patch";
24 url = "https://github.com/stedolan/jq/pull/2292/commits/f6a69a6e52b68a92b816a28eb20719a3d0cb51ae.patch";
25 sha256 = "pTM5FZ6hFs5Rdx+W2dICSS2lcoLY1Q//Lan3Hu8Gr58=";
26 })
27 ];
28
29 outputs = [ "bin" "doc" "man" "dev" "lib" "out" ];
30
31 # Upstream script that writes the version that's eventually compiled
32 # and printed in `jq --help` relies on a .git directory which our src
33 # doesn't keep.
34 preConfigure = ''
35 echo "#!/bin/sh" > scripts/version
36 echo "echo ${version}" >> scripts/version
37 patchShebangs scripts/version
38 '';
39
40 # paranoid mode: make sure we never use vendored version of oniguruma
41 # Note: it must be run after automake, or automake will complain
42 preBuild = ''
43 rm -r ./modules/oniguruma
44 '';
45
46 buildInputs = lib.optionals onigurumaSupport [ oniguruma ];
47 nativeBuildInputs = [ autoreconfHook ];
48
49 configureFlags = [
50 "--bindir=\${bin}/bin"
51 "--sbindir=\${bin}/bin"
52 "--datadir=\${doc}/share"
53 "--mandir=\${man}/share/man"
54 ] ++ lib.optional (!onigurumaSupport) "--with-oniguruma=no"
55 # jq is linked to libjq:
56 ++ lib.optional (!stdenv.isDarwin) "LDFLAGS=-Wl,-rpath,\\\${libdir}";
57
58 doInstallCheck = true;
59 installCheckTarget = "check";
60
61 postInstallCheck = ''
62 $bin/bin/jq --help >/dev/null
63 $bin/bin/jq -r '.values[1]' <<< '{"values":["hello","world"]}' | grep '^world$' > /dev/null
64 '';
65
66 passthru = { inherit onigurumaSupport; };
67
68 meta = with lib; {
69 description = "A lightweight and flexible command-line JSON processor";
70 homepage = "https://stedolan.github.io/jq/";
71 license = licenses.mit;
72 maintainers = with maintainers; [ raskin globin ];
73 platforms = platforms.unix;
74 downloadPage = "https://stedolan.github.io/jq/download/";
75 };
76}