Add build input to a nixpkg

I’ve already checked out this: How to add extra build input to linux kernel?

I’m trying to install dwm-flexipatch, my config on it and all.
I tried a couple methods so far:

  • overrideAttrs (works for changing source to my location of the source, does not work for adding an extra build input)
  • override (I don’t know how this works)
  • overrideDerivation (this is the only one that doesn’t give me an error when rebuilding NixOS for syntax, but it gives the following error).
  nixpkgs.overlays = [
  	#(final: prev:{
  #dwm = prev.dwm.overrideAttrs (old: { 
  	#src = /home/amon/proj/home/clones/dwm-flexipatch; 
	##buildInputs = prev.buildInputs ++ [ pkgs.imlib2 ]; 
	(final: prev: {
	dwm = prev.dwm.overrideDerivation (drv: {
  	src = /home/amon/proj/home/clones/dwm-flexipatch; 
	buildInputs = (drv.buildInputs or []) ++ [ pkgs.imlib2 ]; 
copying path '/nix/store/na4iw08x9qxmvdsbvmb46109wbp3f7cx-imlib2-1.12.1-bin' from ''...
building '/nix/store/992vccp0iw07sr15ayqrwl7q1m5bskp2-dwm-6.4.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/bsmjxiik8ld2rg7428f37caajzb6y06g-dwm-flexipatch
source root is dwm-flexipatch
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
no configure script, doing nothing
Running phase: buildPhase
build flags: SHELL=/nix/store/r9h133c9m8f6jnlsqzwf89zg9w0w78s8-bash-5.2-p15/bin/bash CC=cc
cc -c -std=c99 -pedantic -Wall -Wno-unused-function -Wno-deprecated-declarations -Os -I/usr/X11R6/include -I/usr/include/freetype2    -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"6.4\" -DXINERAMA drw.c
cc -c -std=c99 -pedantic -Wall -Wno-unused-function -Wno-deprecated-declarations -Os -I/usr/X11R6/include -I/usr/include/freetype2    -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"6.4\" -DXINERAMA dwm.c
In file included from patch/include.h:52,
                 from dwm.c:749:
patch/bar_winicon.h:1:10: fatal error: Imlib2.h: No such file or directory
    1 | #include <Imlib2.h>
      |          ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:18: dwm.o] Error 1
error: builder for '/nix/store/992vccp0iw07sr15ayqrwl7q1m5bskp2-dwm-6.4.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/ca2da8z8j5qfpf9fqb33s98kvdkd2pqa-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/pqi8d7707yyp0lvly2yf8mx67isq5hn1-nixos-system-nixos-23.11.4976.79baff8812a0.drv' failed to build

I’m pretty sure you want overrideAttrs here.

In your commented-out attempt, you attempt to reference prev.buildInputs; try old.buildInputs instead.

Also, when creating an overlay, reference other packages from final, not from pkgs. That way, if you have multiple overlays, they’ll all form a consistent package set and you won’t be importing some dependencies from un-overlay-ed Nixpkgs. (The dwm = prev.dwm... is correct though.)

This might not solve the problem with #include <Imlib2.h>, but it’ll be a saner starting point for diagnosis.

nixpkgs.overlays = [
  (final: prev: {
    dwm = prev.dwm.overrideAttrs (old: {
      src = /home/amon/proj/home/clones/dwm-flexipatch;
      buildInputs = old.buildInputs ++ [ pkgs.imlib2 ];

old contains the attrs of the package before the overrideAttrs, prev contains the packages in nixpkgs before the overlay is applied. So you explicitly didn’t retain the old buildInputs, but substituted some random list and added a package. I’m honestly surprised old.buildInputs does not give you an error, but hey.

That allows you to change the arguments of the function given to the callPackage call, so the variables in e.g. these lines:

So, probably not what you want in this case.

1 Like

Alright, so this managed to fix the error, I don’t get the imlib2 not found error anymore. Now there’s other errors from other libraries I need to add, I’ll try to get those sorted on my own, I’ll report back if any problems.

Thank you so much for the reply!


Ohhhh, ok that makes sense. I understand how that could be used, but I was just jumping through all the wiki pages and manual pages trying to understand what does what.