this post was submitted on 10 Feb 2026
7 points (100.0% liked)

Nix / NixOS

2623 readers
16 users here now

Main links

Videos

founded 2 years ago
MODERATORS
 

RESOLVED: see the edit at the bottom of the post for the solution.

Forgive me if this is not the place to ask this question. If that is the case, I would appreciate some help finding the best place to ask.

I wish to start hacking together a wayland compositor in C and I figured wlroots would be a reasonable place to start. I'm using NixOS with flakes and wish to make a dev shell. Here is the flake.nix that I wrote and figured would work:

# flake.nix
{
  description = "wayland compositor";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    { self, nixpkgs, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
      };
    in {
      devShells."${system}".default =
        (pkgs.mkShell {
          buildInputs = with pkgs; [
            # c tools
            clang-tools
            gcc
            glibc
            gnumake
            gdb
            # wayland tools
            wayland
            wayland-protocols
            wayland-scanner
            wlroots
          ];
        });
    };
}

The problem I am having is that I have to include wlroots headers using:

# some c file
#include <wlroots-0.19/wlr/backend.h>
# note the prefix "wlroots-0.19/"

which differs from how other projects include the shared library on a non-NixOS system. For example, in tinywl, the example compositor in the wlroots repo, wlroots headers are included like this:

# tinywl.c
#include <wlr/backend.h>

Furthermore, even if I do include wlroots headers using the first path, I am unable to build anything since those headers have includes like in tinywl.c.

I might be a little bit out of my depth and that's okay, but I was hoping to have fun hacking together a wayland compositor.

Any help would be greatly appreciated.

EDIT: Per this comment I just needed to add pkg-config to my flake and use pkg-config --cflags wlroots-0.19 to get the right flags for my C compiler. The program still failed to build but only because wlroots depends on the pixman library, so once I included that in the flake as well, compilation succeeded. My flake looks like this now:

{
  description = "wayland compositor";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    { self, nixpkgs, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
      };
    in {
      devShells."${system}".default =
        (pkgs.mkShell {
          packages = with pkgs; [
            # for wayland
            pixman
            wlroots
            wayland
            wayland-protocols
            wayland-scanner
            # for c
            pkg-config
            clang-tools
            gcc
            glibc
            gnumake
            gdb
          ];
        });
    };
}
top 6 comments
sorted by: hot top controversial new old
[–] stupiv@lemmy.ml 2 points 4 days ago (1 children)

Do you know about pkg-config --cflags?

    devShells.${system}.default = pkgs.mkShell {
      buildInputs = with pkgs; [
        pkg-config
        clang
        wlroots_0_19
      ];
    };

pkg-config --cflags wlroots-0.19 outputs -I/nix/store/pkg-hash-wlroots-0.19.0/include/wlroots-0.19

clang your-file.c $(pkg-config --cflags wlroots-0.19) should resolve #include <wlr/backend.h>

THANK YOU

That was what I was missing. I am newish to C and had not heard of pkg-config. I will update my post and read more about it.

[–] Laser@feddit.org 3 points 5 days ago (1 children)

Are you also building your project using nix?

For now, I'm building using just gcc and make while I learn the intricacies of wayland/wlroots.

[–] hallettj@leminal.space 1 points 4 days ago (1 children)

I'm taking some stabs in the dark here. I think that mkShell gives you gcc automatically, wrapped with configuration for C header lookup paths. I think it does the same setup as pkgs.stdenv. Including gcc explicitly might be shadowing that configured gcc? Try removing gcc from your buildInputs.

Another thing to maybe try: I don't see wlroots in a package search, but I do see packages with version suffixes, like wlroots_0_19. So maybe try changing wlroots to wlroots_0_19 or wlroots_0_19.dev

I did not know that about gcc and mkShell so that's good to know, thank you. Removing it did not solve the issue however.

It appears that wlroots and wlroots_0_19 evaluate to the same package and neither cause any errors when entering the dev shell. I tried the one with the version number though, but with the same issue. wlroots_0_19.dev also doesn't seem to exist.

I appreciate the suggestions though!