Can't compile dwm: X11/Xlib.h not found

Hi there!

I’m sure this is just me not understanding Library installation with NixOS yet, so it’s most likely my inability to figure things out.

I would like to patch dwm to my liking, before I install it as a custom package from GitHub and use that as my windowmanager. I would also like to know if my patched version even compiles. However, when I run make, I get an error saying, that X11/Xlib.h was not found. Here is the full compiler-output:

dwm build options:
CFLAGS   = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os -I/usr/X11R6/include -I/usr/include/freetype2 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION="6.2" -DXINERAMA
LDFLAGS  = -L/usr/X11R6/lib -lX11 -lXinerama -lfontconfig -lXft
CC       = cc
cc -c -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os -I/usr/X11R6/include -I/usr/include/freetype2 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"6.2\" -DXINERAMA drw.c
drw.c:5:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
make: *** [Makefile:18: drw.o] Error 1

I have installed xorg.libX11 and xorg.libX11.dev on my system, after reading this post, however this doesn’t change the error-message.

What did I miss? Am I going about this the wrong way?

I’m happy to provide further information, if needed.

You need to add it to the derivation you are building, you do not install libraries in the system that doesn’t work in nix.

Libraries are always only used as inputs to your packages.

If you don’t write your own package yet, use a nix-shell first that provides all the inputs you need.

Ok, so in NixOS I write a derivation for every piece of software, that I want to compile. I don’t install libraries to make sure I can just run make. Did I get that right?

You do not need to write a derivation for it, though at least you need to use a shell that holds all required build inputs.

If you want to install though, you won’t have much luck with make install or similar, then you really need to wrap in a derivation.

Great, thanks for the information! :slight_smile: I will try that.

Great news: I learned (at a VERY basic level) how to use nix-shell! The idea of encapsulated development environments is so great! That’s what I’ve been using with python-virtual environments for a few years now. Having that for EVERY development environment is just crazy clean, from a system-state point of view. Here’s my current shell.nix:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    nativeBuildInputs = with pkgs; [
      gnumake
      xorg.libX11.dev
      xorg.libXft
      xorg.libXinerama
    ];
}

Do you think there’s something to be improved there?

After successfully compiling dwm, I include the diff in configuration.nix:

diff -up dwm-6.2/config.def.h dwm-6.2-patched/config.def.h > dwm.diff

I copy that to /etc/nixos/dwm.diff and add this to /etc/nixos/configuration.nix:

  environment = {
    systemPackages = with pkgs; [
      dwm
    ];
  };

  nixpkgs = {
    config = {
      dwm = {
        patches = [ ./dwm.diff ];
      };
    };
  };

I use startx, but you can also set services.xserver.windowManager.dwm.enable to true to select it from the login screen of your DM.

Since dwm releases are so infrequent, this isn’t a burden to maintain and avoids the need to manage a custom package anywhere.

1 Like

Ah yes, that’s great too! Under arch, I wrote a script, that would download and patch dwm the way I wanted it to work (with custom patches and stuff). This way I have kind of an immutable dwm-patcher (add new patch and patch from the beginning, instead of patching an already patched dwm. You‘ll have a hard time finding out where it actually went wrong this way).

What I do now is, that I push the build of the patch to another repo, which then gets included in an overlay to dwm in my configuration.nix. A better way would be to push the patched files to a „src“-branch of the same repository and include that branch in my configuration.nix. Will change that up later today.

Today I learned: You can implicitly override parameters for some packages through nixpkgs.config. This is not documented anywhere as far as I can tell, had to find out with rg config\. /pkgs/top-level/all-packages.nix!`