Search code examples
gtk2nixnixos

How to install libgtk2.0-dev on NixOS?


I'm trying to build this application from source: https://gitlab.com/TheFrozenWatchers/LeagueDisplays

Whenever I try running the make command, it fails with 'gtk/gtk.h' file not found. Is there a known way to install libgtk2.0-dev in Nix (the lack of which I'm assuming is the issue here)?

For reference, I'm using these nix-shell arguments: nix-shell -p xorg.libX11 gtk2. I imagine libgtk2 isn't included in the gtk2 package, but I'm not sure how to actually get the proper headers into the environment for this to work.


Solution

  • Here's a shell.nix you can use:

    with import <nixpkgs> {};
    
    stdenv.mkDerivation rec {
      name = "league-displays-${version}";
      version = "master";
    
      src = ./.;
    
      doCheck = true;
    
      nativeBuildInputs = [ pkgconfig ];
      buildInputs = [ gtk2-x11 clang rapidjson ];
    
      preBuild = ''
        substituteAllInPlace src/themes_service.h --replace "include/rapidjson/document.h" "rapidjson/document.h"
        substituteInPlace Makefile --replace "pkg-config --libs --cflags gtk+-2.0" "pkg-config --libs --cflags gtk+-2.0 RapidJSON"
      '';
    }
    

    When you enter the shell, instead of make run buildPhase. That way the preBuild step runs and applies some patches.

    Even though I've accounted for all known dependencies, the project still doesn't build due to what appears to be some app-specific errors:

    build flags: SHELL=/nix/store/mcyvp1s45scjkkhyb1m16aqlsb8wr6hs-bash-interactive-4.4-p23/bin/bash
    clang++ -O3 -g -w -I. -I./src/ -Wl,-rpath,. -L./bin/ -std=c++14 -Wall -lX11 -lXt -lcef -pthread -lrt -lz `pkg-config --libs --cflags gtk+-2.0 RapidJSON` -I./thirdparty/ -c src/background_daemon.cc
    src/background_daemon.cc:23:9: error: unknown type name 'AppConfig'
            AppConfig* cfg = AppConfig::Acquire();
            ^
    src/background_daemon.cc:23:26: error: use of undeclared identifier 'AppConfig'
            AppConfig* cfg = AppConfig::Acquire();
                             ^
    src/background_daemon.cc:26:9: error: use of undeclared identifier 'AppConfig'
            AppConfig::Release();
            ^
    src/background_daemon.cc:71:9: error: unknown type name 'AppConfig'
            AppConfig* cfg;
            ^
    src/background_daemon.cc:76:19: error: use of undeclared identifier 'AppConfig'
                cfg = AppConfig::Acquire();
                      ^
    src/background_daemon.cc:110:37: error: use of undeclared identifier 'fnvHash'
                    unsigned int hash = fnvHash(wp.c_str());
                                        ^
    src/background_daemon.cc:133:13: error: use of undeclared identifier 'AppConfig'
                AppConfig::Release();
                ^
    7 errors generated.
    make: *** [Makefile:37: background_daemon.o] Error 1