at 23.05-pre 106 lines 3.8 kB view raw
1{ lib, stdenv, fetchurl, zlib, readline, ncurses 2 3# for tests 4, python3Packages, sqldiff, sqlite-analyzer 5 6# uses readline & ncurses for a better interactive experience if set to true 7, interactive ? false 8# TODO: can be removed since 3.36 since it is the default now. 9, enableDeserialize ? false 10}: 11 12with lib; 13 14let 15 archiveVersion = import ./archive-version.nix lib; 16in 17 18stdenv.mkDerivation rec { 19 pname = "sqlite${optionalString interactive "-interactive"}"; 20 version = "3.39.4"; 21 22 # nixpkgs-update: no auto update 23 # NB! Make sure to update ./tools.nix src (in the same directory). 24 src = fetchurl { 25 url = "https://sqlite.org/2022/sqlite-autoconf-${archiveVersion version}.tar.gz"; 26 sha256 = "sha256-8x1EW0jmfihM8gZxfMFwq2PL5P1/eagnk7dyKF54/bs="; 27 }; 28 29 outputs = [ "bin" "dev" "out" ]; 30 separateDebugInfo = stdenv.isLinux; 31 32 buildInputs = [ zlib ] ++ optionals interactive [ readline ncurses ]; 33 34 # required for aarch64 but applied for all arches for simplicity 35 preConfigure = '' 36 patchShebangs configure 37 ''; 38 39 configureFlags = [ "--enable-threadsafe" ] ++ optional interactive "--enable-readline"; 40 41 NIX_CFLAGS_COMPILE = toString ([ 42 "-DSQLITE_ENABLE_COLUMN_METADATA" 43 "-DSQLITE_ENABLE_DBSTAT_VTAB" 44 "-DSQLITE_ENABLE_JSON1" 45 "-DSQLITE_ENABLE_FTS3" 46 "-DSQLITE_ENABLE_FTS3_PARENTHESIS" 47 "-DSQLITE_ENABLE_FTS3_TOKENIZER" 48 "-DSQLITE_ENABLE_FTS4" 49 "-DSQLITE_ENABLE_FTS5" 50 "-DSQLITE_ENABLE_RTREE" 51 "-DSQLITE_ENABLE_STMT_SCANSTATUS" 52 "-DSQLITE_ENABLE_UNLOCK_NOTIFY" 53 "-DSQLITE_SOUNDEX" 54 "-DSQLITE_SECURE_DELETE" 55 "-DSQLITE_MAX_VARIABLE_NUMBER=250000" 56 "-DSQLITE_MAX_EXPR_DEPTH=10000" 57 ] ++ lib.optionals enableDeserialize [ 58 # Can be removed in v3.36+, as this will become the default 59 "-DSQLITE_ENABLE_DESERIALIZE" 60 ]); 61 62 # Test for features which may not be available at compile time 63 preBuild = '' 64 # Use pread(), pread64(), pwrite(), pwrite64() functions for better performance if they are available. 65 if cc -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread_pwrite_test" <<< \ 66 ''$'#include <unistd.h>\nint main()\n{\n pread(0, NULL, 0, 0);\n pwrite(0, NULL, 0, 0);\n return 0;\n}'; then 67 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD" 68 fi 69 if cc -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread64_pwrite64_test" <<< \ 70 ''$'#include <unistd.h>\nint main()\n{\n pread64(0, NULL, 0, 0);\n pwrite64(0, NULL, 0, 0);\n return 0;\n}'; then 71 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD64" 72 elif cc -D_LARGEFILE64_SOURCE -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread64_pwrite64_test" <<< \ 73 ''$'#include <unistd.h>\nint main()\n{\n pread64(0, NULL, 0, 0);\n pwrite64(0, NULL, 0, 0);\n return 0;\n}'; then 74 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD64 -D_LARGEFILE64_SOURCE" 75 fi 76 77 # Necessary for FTS5 on Linux 78 export NIX_LDFLAGS="$NIX_LDFLAGS -lm" 79 80 echo "" 81 echo "NIX_CFLAGS_COMPILE = $NIX_CFLAGS_COMPILE" 82 echo "" 83 ''; 84 85 postInstall = '' 86 # Do not contaminate dependent libtool-based projects with sqlite dependencies. 87 sed -i $out/lib/libsqlite3.la -e "s/dependency_libs=.*/dependency_libs='''/" 88 ''; 89 90 doCheck = false; # fails to link against tcl 91 92 passthru.tests = { 93 inherit (python3Packages) sqlalchemy; 94 inherit sqldiff sqlite-analyzer; 95 }; 96 97 meta = { 98 description = "A self-contained, serverless, zero-configuration, transactional SQL database engine"; 99 downloadPage = "https://sqlite.org/download.html"; 100 homepage = "https://www.sqlite.org/"; 101 license = licenses.publicDomain; 102 mainProgram = "sqlite3"; 103 maintainers = with maintainers; [ eelco np ]; 104 platforms = platforms.unix ++ platforms.windows; 105 }; 106}