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