From be6364c2815d1d60cacef4b79be16a438cc22905 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 19 May 2026 22:02:03 +0900 Subject: [PATCH] Render headers as their own derivation --- src/headers.nix | 63 +++++++++++++++++++++++++++++++++++++++++++++++ src/mk-sqlite.nix | 11 +++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/headers.nix diff --git a/src/headers.nix b/src/headers.nix new file mode 100644 index 0000000..ad69ccc --- /dev/null +++ b/src/headers.nix @@ -0,0 +1,63 @@ +{ + lib, + + src, + version, + nameSuffix, + + stdenv, + + unzip, + tcl, + zlib, + icu, + + features ? { }, + featureFlags ? [ ], + + ... +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "sqlite-amalgamation${nameSuffix}"; + inherit version src; + + nativeBuildInputs = [ + unzip + tcl + ]; + + buildInputs = [ + zlib + ] ++ lib.optional features.ENABLE_ICU [ + icu + ]; + + # required for aarch64 but applied for all arches for simplicity + preConfigure = '' + patchShebangs configure + ''; + + # sqlite relies on autosetup now; so many of the + # previously-understood flags are gone. They should instead be set + # on a per-output basis. + setOutputFlags = false; + + configureFlags = lib.optional features.ENABLE_ICU [ + "--enable-icu-collations" + "--with-icu-config=${lib.getExe' icu.dev "icu-config"}" + ]; + + env.NIX_CFLAGS_COMPILE = lib.concatStringsSep " " featureFlags; + env.NIX_CFLAGS_LINK = lib.optionalString features.ENABLE_FTS5 "-lm"; + + makeFlags = [ "sqlite3.h" ]; + + installPhase = '' + runHook preInstall + + install -Dm444 sqlite3.h src/sqlite3ext.h -t "$out/include" + + runHook postInstall + ''; +}) diff --git a/src/mk-sqlite.nix b/src/mk-sqlite.nix index a02f49a..4dea3c0 100644 --- a/src/mk-sqlite.nix +++ b/src/mk-sqlite.nix @@ -63,6 +63,15 @@ let (x: if x == "" then "" else "-${x}") ]; + headers = pkgs.callPackage ./headers.nix ({ + inherit version src; + inherit amalgamate; + inherit features; + inherit extensions; + inherit extraLibraries; + nameSuffix = suffix; + } // config); + coreInitExt = if extensions == [ ] then null else pkgs.callPackage ./core-init-ext.nix ({ @@ -76,6 +85,8 @@ in { _suffix = suffix; _coreInitExt = coreInitExt; + inherit headers; + sqlite = pkgs.callPackage ./sqlite.nix ({ inherit version src; inherit amalgamate;