Glib not found in cargo compilation

hi friends

new to nixOS so this may be a question with an obvious solution.

i’m trying to compile and run my rust package using cargo (which was installed via rustup). i’ve installed pkg-config and glib via environment.systemPackages. you can see my configuration here

when i run the compilation command, the error raised is:

error: failed to run custom build command for `glib-sys v0.5.0`

Caused by:
  process didn't exit successfully: `/home/josh/coding/rust/caydence/target/release/build/glib-sys-e8db584016130499/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=GLIB_2.0_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=GLIB_2.0_STATIC
  cargo:rerun-if-env-changed=GLIB_2.0_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr

  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags glib-2.0 glib-2.0 >= 2.32

  The system library `glib-2.0` required by crate `glib-sys` was not found.
  The file `glib-2.0.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  The PKG_CONFIG_PATH environment variable is not set.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `glib-2.0.pc`.

any help would be greatly appreciated!

See General method of converting shell.nix solutions to global solutions - #2 by rgoulter

1 Like

ah, thank you! a follow on question, if you don’t mind: where is the line generally drawn for what should be installed globally? should i even have the rust toolchain installed with rustup?

I would say that if your goal is to eventually build a Nix derivation for the project, you should not install any development dependencies globally. You should instead create a shell.nix (or flake.nix with devShell output, if you are into flakes), since that will make it easy to turn into a Nix derivation.

If you just want to develop the project or run it without installation, you are not really bound by Nix’s reproducibility requirements and can get dependencies from wherever. But once you need non-Rust library dependencies, you will still need a Nix shell, so you might as well install the Rust toolchain through it too.

But it really depends on how much do you want to buy in into the Nix ecosystem, care about reproducibility, or if you want to have single rollbackable configuration for the development environment. If you are already familiar with rustup, installing it globally and getting specific Rust compiler version through will be easier than figuring out something like Fenix. Maybe rust-toolchain.toml will give you sufficient reproducibility (I do not know what guarantees it provides).

1 Like