nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, fetchurl, zlib, interactive ? false, readline, ncurses
2, python3Packages
3, enableDeserialize ? false
4, sqldiff, sqlite-analyzer
5}:
6
7with lib;
8
9let
10 archiveVersion = import ./archive-version.nix lib;
11in
12
13stdenv.mkDerivation rec {
14 pname = "sqlite${optionalString interactive "-interactive"}";
15 version = "3.38.5";
16
17 # nixpkgs-update: no auto update
18 # NB! Make sure to update ./tools.nix src (in the same directory).
19 src = fetchurl {
20 url = "https://sqlite.org/2022/sqlite-autoconf-${archiveVersion version}.tar.gz";
21 sha256 = "sha256-WvB96YK6ZY/ZGgMXDJRfmclx9pVbx53zJmVENz45hpw=";
22 };
23
24 outputs = [ "bin" "dev" "out" ];
25 separateDebugInfo = stdenv.isLinux;
26
27 buildInputs = [ zlib ] ++ optionals interactive [ readline ncurses ];
28
29 # required for aarch64 but applied for all arches for simplicity
30 preConfigure = ''
31 patchShebangs configure
32 '';
33
34 configureFlags = [ "--enable-threadsafe" ] ++ optional interactive "--enable-readline";
35
36 NIX_CFLAGS_COMPILE = toString ([
37 "-DSQLITE_ENABLE_COLUMN_METADATA"
38 "-DSQLITE_ENABLE_DBSTAT_VTAB"
39 "-DSQLITE_ENABLE_JSON1"
40 "-DSQLITE_ENABLE_FTS3"
41 "-DSQLITE_ENABLE_FTS3_PARENTHESIS"
42 "-DSQLITE_ENABLE_FTS3_TOKENIZER"
43 "-DSQLITE_ENABLE_FTS4"
44 "-DSQLITE_ENABLE_FTS5"
45 "-DSQLITE_ENABLE_RTREE"
46 "-DSQLITE_ENABLE_STMT_SCANSTATUS"
47 "-DSQLITE_ENABLE_UNLOCK_NOTIFY"
48 "-DSQLITE_SOUNDEX"
49 "-DSQLITE_SECURE_DELETE"
50 "-DSQLITE_MAX_VARIABLE_NUMBER=250000"
51 "-DSQLITE_MAX_EXPR_DEPTH=10000"
52 ] ++ lib.optionals enableDeserialize [
53 # Can be removed in v3.36+, as this will become the default
54 "-DSQLITE_ENABLE_DESERIALIZE"
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.tests = {
88 inherit (python3Packages) sqlalchemy;
89 inherit sqldiff sqlite-analyzer;
90 };
91
92 meta = {
93 description = "A self-contained, serverless, zero-configuration, transactional SQL database engine";
94 downloadPage = "https://sqlite.org/download.html";
95 homepage = "https://www.sqlite.org/";
96 license = licenses.publicDomain;
97 mainProgram = "sqlite3";
98 maintainers = with maintainers; [ eelco np ];
99 platforms = platforms.unix ++ platforms.windows;
100 };
101}