-1

When i try to install the diesel-cli with

cargo install diesel_cli --no-default-features --features sqlite

under NixOS, i get

error: linking with `cc` failed: exit status: 1
...
 = note: /nix/store/kmqs0wll31ylwbqkpmlgbjrn6ny3myik-binutils-2.35.1/bin/ld: cannot find -lsqlite3
          collect2: error: ld returned 1 exit status

even though the Nix packages sqlite and pkg-config are installed. To me this looks like sqlite missing its static libraries, however i don't see any flag to enable in https://github.com/NixOS/nixpkgs/blob/nixos-21.05/pkgs/development/libraries/sqlite/default.nix.

Note:

  1. Installing the postgres nix package and compiling the diesel-cli with
cargo install diesel_cli --no-default-features --features postgres

works flawlessly.

  1. A workaround install the diesel-cli is using the Nix package of the same name https://github.com/NixOS/nixpkgs/blob/nixos-21.05/pkgs/development/tools/diesel-cli/default.nix which comes with enabled sqlite support. Nevertheless, i would like know how to compile it myself, and trying to compile the Rust project will fail with the same error above.
manews
  • 340
  • 2
  • 12
  • Do you have the nix `sqlite` package installed at all, either in the global environment or in the current shell? – justinas Oct 10 '21 at 13:10
  • Sorry, I did not noticed you have already noted that in your question. Please see if my answer helps. – justinas Oct 10 '21 at 17:33

1 Answers1

0

The compilation seems to work using the following shell.nix:

{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
  buildInputs = with pkgs; [ cargo rustc pkg-config sqlite ];
}

If you only have sqlite and/or pkg-config installed globally instead, that might be what's causing problems. The pkg-config derivation sets some environment variables:

$ env | grep PKG_CONFIG
NIX_PKG_CONFIG_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu=1
PKG_CONFIG_FOR_TARGET=pkg-config

and I do not think these are set if you use globally installed packages.

justinas
  • 6,287
  • 3
  • 26
  • 36
  • Thanks. That was it. I extended the Nix documentation https://nixos.wiki/wiki/Rust and https://nixos.wiki/wiki/FAQ/I_installed_a_library_but_my_compiler_is_not_finding_it._Why%3F – manews Oct 10 '21 at 20:28