1{ lib, stdenv, fetchurl, zlib, interactive ? false, readline ? null, ncurses ? null
2, python3Packages
3}:
4
5assert interactive -> readline != null && ncurses != null;
6
7with lib;
8
9let
10 archiveVersion = import ./archive-version.nix lib;
11in
12
13stdenv.mkDerivation rec {
14 pname = "sqlite";
15 version = "3.35.2";
16
17 # NB! Make sure to update ./tools.nix src (in the same directory).
18 src = fetchurl {
19 url = "https://sqlite.org/2021/sqlite-autoconf-${archiveVersion version}.tar.gz";
20 sha256 = "1bfczv5006ycwr1vw7xbq7cmys0jvfr8awmx7wi1b40zyj0yss8j";
21 };
22
23 outputs = [ "bin" "dev" "out" ];
24 separateDebugInfo = stdenv.isLinux;
25
26 buildInputs = [ zlib ] ++ optionals interactive [ readline ncurses ];
27
28 configureFlags = [ "--enable-threadsafe" ] ++ optional interactive "--enable-readline";
29
30 NIX_CFLAGS_COMPILE = toString [
31 "-DSQLITE_ENABLE_COLUMN_METADATA"
32 "-DSQLITE_ENABLE_DBSTAT_VTAB"
33 "-DSQLITE_ENABLE_JSON1"
34 "-DSQLITE_ENABLE_FTS3"
35 "-DSQLITE_ENABLE_FTS3_PARENTHESIS"
36 "-DSQLITE_ENABLE_FTS3_TOKENIZER"
37 "-DSQLITE_ENABLE_FTS4"
38 "-DSQLITE_ENABLE_FTS5"
39 "-DSQLITE_ENABLE_RTREE"
40 "-DSQLITE_ENABLE_STMT_SCANSTATUS"
41 "-DSQLITE_ENABLE_UNLOCK_NOTIFY"
42 "-DSQLITE_SOUNDEX"
43 "-DSQLITE_SECURE_DELETE"
44 "-DSQLITE_MAX_VARIABLE_NUMBER=250000"
45 "-DSQLITE_MAX_EXPR_DEPTH=10000"
46 ];
47
48 # Test for features which may not be available at compile time
49 preBuild = ''
50 # Use pread(), pread64(), pwrite(), pwrite64() functions for better performance if they are available.
51 if cc -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread_pwrite_test" <<< \
52 ''$'#include <unistd.h>\nint main()\n{\n pread(0, NULL, 0, 0);\n pwrite(0, NULL, 0, 0);\n return 0;\n}'; then
53 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD"
54 fi
55 if cc -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread64_pwrite64_test" <<< \
56 ''$'#include <unistd.h>\nint main()\n{\n pread64(0, NULL, 0, 0);\n pwrite64(0, NULL, 0, 0);\n return 0;\n}'; then
57 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD64"
58 elif cc -D_LARGEFILE64_SOURCE -Werror=implicit-function-declaration -x c - -o "$TMPDIR/pread64_pwrite64_test" <<< \
59 ''$'#include <unistd.h>\nint main()\n{\n pread64(0, NULL, 0, 0);\n pwrite64(0, NULL, 0, 0);\n return 0;\n}'; then
60 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DUSE_PREAD64 -D_LARGEFILE64_SOURCE"
61 fi
62
63 # Necessary for FTS5 on Linux
64 export NIX_LDFLAGS="$NIX_LDFLAGS -lm"
65
66 echo ""
67 echo "NIX_CFLAGS_COMPILE = $NIX_CFLAGS_COMPILE"
68 echo ""
69 '';
70
71 postInstall = ''
72 # Do not contaminate dependent libtool-based projects with sqlite dependencies.
73 sed -i $out/lib/libsqlite3.la -e "s/dependency_libs=.*/dependency_libs='''/"
74 '';
75
76 doCheck = false; # fails to link against tcl
77
78 passthru.tests = {
79 inherit (python3Packages) sqlalchemy;
80 };
81
82 meta = {
83 description = "A self-contained, serverless, zero-configuration, transactional SQL database engine";
84 downloadPage = "https://sqlite.org/download.html";
85 homepage = "https://www.sqlite.org/";
86 license = licenses.publicDomain;
87 maintainers = with maintainers; [ eelco np ];
88 platforms = platforms.unix ++ platforms.windows;
89 };
90}