Doom Emacs: emacsql-sqlite not found when running ~/.emacs.d/bin/doom doctor command

Hey all,

I am a relatively new NixOS user (~1 month), and I am trying to use Doom Emacs on NixOS. While most of the time it works quite well, I have issues, when I try and check what common problems my config may be encountering by running ~/.emacs.d/bin/doom doctor or doom doctor for short. The error is:

      Message: error
      Error: (error "No EmacSQL SQLite binary available, aborting")
        (signal error ("No EmacSQL SQLite binary available, aborting"))
        (error "No EmacSQL SQLite binary available, aborting")
        (byte-code "\3001\n\301 \210\3020\207\303\304\"\210\305\207" [(debug err...
        (defconst code-review-db--sqlite-available-p (byte-code "\3001\n\301 \210...
        (#<subr require> code-review-db)
        (apply #<subr require> code-review-db)
        (progn (fset #'write-region vnew) (apply fn args))
        (unwind-protect (progn (fset #'write-region vnew) (apply fn args)) (fset #...
        (let* ((vnew #'(lambda (start end filename &optional append visit lockname...```

If it helps, I am running Emacs 27.2 and have sqlite installed in configuration.nix like so:

environment.systemPackages = with pkgs; [

Thanks so much for any insight you all have.

How do you install/start Emacs/doom?

If you’re using home-manager’s user service, for example, Emacs will be started with an empty path, making anything you install using environment.systemPackages unavailable without a bit more tinkering.

There is also this community project, which is probably easier than rolling your own: GitHub - nix-community/nix-doom-emacs: doom-emacs packaged for Nix [maintainer=@ckiee]

In the backtrace you’ve posted, there’s a function called emacsql-sqlite-ensure-binary. That function belongs to the emacsql-sqlite package [1], and it builds C source files included in the package itself [2]. The resulting binary is what is being referred to as the “EmacSQL SQLite binary” in the error message. Including SQLite in environment.systemPackages has no effect because emacsql-sqlite isn’t making use of the official SQLite command.

My preferred method of dealing with packages like emacsql-sqlite that include native C code would be to obtain them from Nixpkgs. Nixpkgs would precompile those C code so that you wouldn’t need to expose C compilers to the global PATH.

Assuming you use configuration.nix to install Emacs, change your configuration to something like the below:

{ config, pkgs, ... }:

  myEmacs = pkgs.emacsWithPackages (epkgs: with epkgs; [
  environment.systemPackages = [ myEmacs ];

Then, tell Doom Emacs to prefer the Nixpkgs copy of emacsql-sqlite by adding the following to $DOOMDIR/packages.el:

(package! emacsql-sqlite :built-in 'prefer)

Finally, run doom sync -p to reflect the change.

[1]: not to be confused with emacsql-sqlite3
[2]: emacsql/emacsql-sqlite.el at 6d8cd9366284b5a27268ff4b783e2c34573d5b60 · skeeto/emacsql · GitHub

1 Like