2026-05-18 23:38:14 +09:00
2026-05-18 23:38:13 +09:00
2026-05-18 23:38:13 +09:00
2026-05-18 23:38:14 +09:00

nix-custom-sqlite

This repository contains a collection of nix expressions that make it easy to compile a custom version of SQLite.

Customizations include things such as:

  • Toggling compile-time features.
  • Adding external plugins, either baking them in statically or using dynamic linking.
  • Cross-compiling for various architectures.

Example usage

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  inputs.nix-sqlite = "git+https://git.pvv.ntnu.no/mugiten/nix-custom-sqlite.git?ref=main";
  inputs.nix-sqlite.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nix-sqlite }: {
    devshells.x86_64-linux.default = let
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      customSqlite = nix-sqlite.mkSqlite {
        # This lets you specify which `pkgs` instance to build from
        pkgs = pkgs;

        # This is particularly useful if you want to build a cross-compiled sqlite:
        # pkgs = import nixpkgs {
        #   allowUnfree = true;
        #   localSystem = "x86_64-linux";
        #   crossSystem = lib.systems.examples.aarch64-android-prebuilt;
        # };

        # By default, we toggle on a bunch of `ENABLE_<OPTION>` feature flags.
        # If you'd rather want to start configuring from nothing, only enabling the
        # stuff you need, you can set this to true and enable the missing pieces in
        # `features`.
        enableMinimal = true;

        # Enabling this will turn on a list of features flags that are useful for debugging.
        enableDebug = false;

        # Enabling this will add libraries 'ncurses' and 'readline' to the sqlite cli executable.
        enableInteractive = true;

        # Setting this to false will make it so that the source code is not amalgamated before
        # compilation. See https://sqlite.org/amalgamation.html for more details about what
        # this entails.
        amalgamate = false;

        # This option lets you enable and disable compile time feature flags for SQLite.
        # See https://sqlite.org/compile.html for a total list of available options.
        #
        # Please note that all `SQLITE_` prefixes have been stripped from the options, so
        # you need to take this into account when translating from the docs to nix code.
        features = {
          ENABLE_FTS5 = true;
          ENABLE_ICU = true;
          SOUNDEX = false;
        };

        # This option lets you bake in both static and dynamic extensions at compile time,
        # resulting in the sqlite binary eagerly loading the extension at startup automatically
        # without needing to `.load` them.
        #
        # Static extensions will be baked into the sqlite library/executable itself, while
        # dynamic extensions will be added to sqlite's rpath.
        extensions = [
          {
            # Path to the .a or .so file that contains the SQLite extension.
            library = "${pkgs.my-custom-extension}/lib/my-custom-extension.a";

            # The symbol pointing to the function that initializes the extension
            init = "sqlite3_init_mycustomextension";

            # The symbol point to the destructor function of the extension (if there is any).
            shutdown = "sqlite3_shutdown_mycustomextension";
          }

          {
            library = "${pkgs.my-custom-extension}/lib/my-other-extension.so";
            init = "sqlite3_init_myotherextension";
          }
        ];
      };
    in pkgs.stdenv.mkShell {
      env.AMALGAMATION_DIR = "${customSqlite.amalgamation}/";

      buildInputs = [
        customSqlite.sqlite
        customSqlite.sqlite-static
      ];

      packages = [
        customSqlite.sqlite-cli
      ];
      ...
    };
  };
}
S
Description
Custom sqlite builds for your custom sqlite needs
Readme 112 KiB
Languages
Nix 91%
C 9%