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