I’ve been using rust for a while and recently wanted to start using plotters for visualization. Unfortunately it looks like this is tricky on nixos due to its dependency on several system based crates. I’ve added most of them, but cargo still fails to build this trivial example below because it can’t build servo-fontconfig
since something relies on /usr/bin/file
which nixos does not have. I’ve tried using naersk as well to build this, but I still run into the same problem (and ideally would like quick development iteration with cargo instead of nix build
the default package.
How can I fix this problem? It seems most likely that I won’t be able to use a simple cargo build
in my nix develop
shell anymore (which I would really like), but I can’t even get naersk or buildRustCrate to work.
flake.nix:
{
description = "Test";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.inputs.nixpkgs.follows = "nixpkgs";
devshell.url = "github:numtide/devshell";
devshell.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, ...}: with inputs;
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlay ]; };
customCmd = p: { package = p; category = "terminal commands"; };
in rec {
devShell = pkgs.devshell.mkShell {
packages = with pkgs; [
cargo rustc nixfmt gcc
gnumake fontconfig freetype expat libxml2 # plotters
];
};
});
}
[package]
name = "plotters_test"
version = "0.1.0"
authors = ["me <example@example.com>"]
edition = "2018"
[dependencies]
plotters = "0.3.1"
src/main.rs:
extern crate plotters;
fn main() {
println!("Hello World!");
}
Command:
❯ cargo build
...
error: failed to run custom build command for `servo-fontconfig-sys v5.1.0`
...
--- stderr
~/.cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-5.1.0/configure: line 7528: /usr/bin/file: No such file or directory
configure: error: in `~/projects/tmp/target/debug/build/servo-fontconfig-sys-afbca9cff405bb2a/out':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Alternatively, you may set the environment variables FREETYPE_CFLAGS
and FREETYPE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See `config.log' for more details
make: *** [makefile.cargo:83: ~/projects/tmp/target/debug/build/servo-fontconfig-sys-afbca9cff405bb2a/out/Makefile] Error 1
thread 'main' panicked at 'assertion failed: Command::new(\"make\").env(\"MAKEFLAGS\",\n env::var(\"CARGO_MAKEFLAGS\").unwrap_or_default()).args(&[\"-R\",\n
\"-f\",\n \"makefile.cargo\"]).status().unwrap().success(
)', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-5.1.0/build.rs:41:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace