at 24.11-pre 84 lines 2.8 kB view raw
1{ lib 2, stdenv 3, fetchurl 4, removeReferencesTo 5, autoreconfHook 6, bison 7, onigurumaSupport ? true 8, oniguruma 9}: 10 11stdenv.mkDerivation rec { 12 pname = "jq"; 13 version = "1.7.1"; 14 15 # Note: do not use fetchpatch or fetchFromGitHub to keep this package available in __bootPackages 16 src = fetchurl { 17 url = "https://github.com/jqlang/jq/releases/download/jq-${version}/jq-${version}.tar.gz"; 18 hash = "sha256-R4ycoSn9LjRD/icxS0VeIR4NjGC8j/ffcDhz3u7lgMI="; 19 }; 20 21 outputs = [ "bin" "doc" "man" "dev" "lib" "out" ]; 22 23 # Upstream script that writes the version that's eventually compiled 24 # and printed in `jq --help` relies on a .git directory which our src 25 # doesn't keep. 26 preConfigure = '' 27 echo "#!/bin/sh" > scripts/version 28 echo "echo ${version}" >> scripts/version 29 patchShebangs scripts/version 30 ''; 31 32 # paranoid mode: make sure we never use vendored version of oniguruma 33 # Note: it must be run after automake, or automake will complain 34 preBuild = '' 35 rm -r ./modules/oniguruma 36 ''; 37 38 buildInputs = lib.optionals onigurumaSupport [ oniguruma ]; 39 nativeBuildInputs = [ removeReferencesTo autoreconfHook bison ]; 40 41 # Darwin requires _REENTRANT be defined to use functions like `lgamma_r`. 42 # Otherwise, configure will detect that they’re in libm, but the build will fail 43 # with clang 16+ due to calls to undeclared functions. 44 # This is fixed upstream and can be removed once jq is updated (to 1.7 or an unstable release). 45 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin (toString [ 46 "-D_REENTRANT=1" 47 "-D_DARWIN_C_SOURCE=1" 48 ]); 49 50 configureFlags = [ 51 "--bindir=\${bin}/bin" 52 "--sbindir=\${bin}/bin" 53 "--datadir=\${doc}/share" 54 "--mandir=\${man}/share/man" 55 ] ++ lib.optional (!onigurumaSupport) "--with-oniguruma=no" 56 # jq is linked to libjq: 57 ++ lib.optional (!stdenv.isDarwin) "LDFLAGS=-Wl,-rpath,\\\${libdir}"; 58 59 # Break the dependency cycle: $dev refers to $bin via propagated-build-outputs, and 60 # $bin refers to $dev because of https://github.com/jqlang/jq/commit/583e4a27188a2db097dd043dd203b9c106bba100 61 postFixup = '' 62 remove-references-to -t "$dev" "$bin/bin/jq" 63 ''; 64 65 doInstallCheck = true; 66 installCheckTarget = "check"; 67 68 postInstallCheck = '' 69 $bin/bin/jq --help >/dev/null 70 $bin/bin/jq -r '.values[1]' <<< '{"values":["hello","world"]}' | grep '^world$' > /dev/null 71 ''; 72 73 passthru = { inherit onigurumaSupport; }; 74 75 meta = with lib; { 76 description = "A lightweight and flexible command-line JSON processor"; 77 homepage = "https://jqlang.github.io/jq/"; 78 license = licenses.mit; 79 maintainers = with maintainers; [ raskin artturin ncfavier ]; 80 platforms = platforms.unix; 81 downloadPage = "https://jqlang.github.io/jq/download/"; 82 mainProgram = "jq"; 83 }; 84}