Specify system dependencies in flake.nix

I am trying to build GitHub - mollyim/mollysocket: MollySocket allows getting Signal notifications via UnifiedPush. using cargo2nix and their minimally modified sample flake.nix:

{
  inputs = {
    cargo2nix.url = "github:cargo2nix/cargo2nix/release-0.11.0";
    flake-utils.follows = "cargo2nix/flake-utils";
    nixpkgs.follows = "cargo2nix/nixpkgs";
  };

  outputs = inputs: with inputs;
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [cargo2nix.overlays.default];
        };

        rustPkgs = pkgs.rustBuilder.makePackageSet {
          rustVersion = "1.75.0";
          packageFun = import ./Cargo.nix;
        };

      in rec {
        packages = {
          mollysocket = (rustPkgs.workspace.mollysocket {});
          default = packages.mollysocket;
        };
      }
    );
}

Building using nix build fails with /nix/store/1fn92b0783crypjcxvdv6ycmvi27by0j-binutils-2.40/bin/ld: cannot find -lsqlite3: No such file or directory. Can I add this to my devShell? I tried running nix build inside the shell created via nix-shell -p pkg-config sqlite, which failed with the same error.

Flakes are pure and will not depend on what you have in your current shell environment. The nix-shell -p ... invocation would help if you were building outside of Nix (e.g. via cargo build)

What you need is some way to define buildInputs / nativeBuildInputs for the specific derivation (mollysocket). Looks like entry number 3 in Common issues provides a way to do this.

1 Like

Thanks for this very pedagogical answer. I’m using

rustPkgs = pkgs.rustBuilder.makePackageSet {
  rustVersion = "1.75.0";
  packageFun = import ./Cargo.nix;
  packageOverrides = pkgs: pkgs.rustBuilder.overrides.all ++ [pkgs.rustBuilder.overrides.libsqlite3-sys];
};

for now until Add override libsqlite3-sys to all by hrdl-github · Pull Request #353 · cargo2nix/cargo2nix · GitHub is accepted.