Build inputs not available in configure step

Hello! I’m new to nix and trying my hand at my first derivation for a package that’s only available from source.

But when i run nix-build on the .nix file i made, I get errors like

> ./configure: line 14397: syntax error near unexpected token `GTK4,'
> ./configure: line 14397: `  PKG_CHECK_MODULES(GTK4, gtk4 >= 4.14)'

or if i disable the UI,

./configure: line 14406: syntax error near unexpected token `libusb,'
./configure: line 14406: `PKG_CHECK_MODULES(libusb, libusb, HAVE_LIBUSB=1, HAVE_LIBUSB=0)'

To me, this means the dependencies are not found? I tried placing them both as buildInputs and nativeBuildInputs it didn’t make a difference.

This is the derivation i’m working with based on some docs and guides i followed.

with import <nixpkgs> { }; # bring all of Nixpkgs into scope

stdenv.mkDerivation rec {
  name = "overwitch";

  # https://github.com/dagargo/overwitch
  src = fetchFromGitHub {
    owner  = "dagargo";
    repo   = "overwitch";
    tag    = "2.2"; 
    sha256 = "EYT5m4N9kzeYaOcm1furGGxw1k+Bw+m+FvONVZN9ohk=";
  };

  nativeBuildInputs = [ autoreconfHook libusb1 gtk4];
  buildInputs = [ autoconf automake gettext libsndfile libtool libjack2 libsamplerate libjson];
  configurePhase = "./configure";
  installFlags = [ "DESTDIR=$(out)" ];
}

This is the package and it’s listed as having the following (debian) dependencies:

automake libtool libusb-1.0-0-dev libjack-jackd2-dev libsamplerate0-dev libsndfile1-dev autopoint gettext libsystemd-dev libjson-glib-dev libgtk-4-dev systemd-dev

For what it’s worth, i tried doing the same with nix-shell and got the same errors, but from what I could tell that’s expected.

NixOS version: 25.05

Thanks in advance!

{
  stdenv,

  fetchFromGitHub,
  autoreconfHook,
  pkg-config,

  libusb1,
  gtk4,
  libjack2,
  libsamplerate,
  libsndfile,
  json-glib,
}:
stdenv.mkDerivation (finalAttrs: {
  src = fetchFromGitHub {
    owner = "dagargo";
    repo = "overwitch";
    rev = "b8f1319daaae65c4badeeb2696d01df2fd5df815";
    hash = "sha256-EYT5m4N9kzeYaOcm1furGGxw1k+Bw+m+FvONVZN9ohk=";
  };

  pname = "overwitch";
  version = "xx-unstable3";

  nativeBuildInputs = [
    autoreconfHook
    pkg-config
  ];

  buildInputs = [
    libusb1
    gtk4
    libjack2
    libsamplerate
    libsndfile
    json-glib
  ];

  installFlags = [
    "DESTDIR=$(out)"
  ];

})

Builds when called via call-package. I have “modernized”(e.g. Packaging Resonarium vst: hash mismatch - #4 by drupol) your derivation in a couple of places (The finalAttrs-construct, replaces your use of rec, but since it was not actually used before it serves no purpose). Looks like you were just missing pkg-config.

2 Likes

Wow thank you so much! I clearly missed those concepts when reading docs, so I’ll read up on call-package and pkg-config. And I’ll see about why I didn’t come across them in the first place

For posterity, I had to make one more change of removing the installFlags. It was causing the object files to not be linked properly at runtime despite being present. Though maybe there’s a way around that too via params to call-package.