How to make a program find GLX?

I’m trying to package Tacent View, which requires GLX. This is what I have so far:

{
    cmake,
    fetchFromGitHub,
    lib,
    ninja,
    pkgs,
    stdenv,
}:

stdenv.mkDerivation rec {
    pname = "tacentview";
    version = "1.0.44";

    src = fetchFromGitHub {
        owner = "bluescan";
        repo = pname;
        rev = "97defc4beec597978fc7df0f2be4ac1bbe9d5bd1";
        hash = "sha256-/nN9S3B1+OgdhwA7X2NHZRQzYMH1VA31S6HpG5sjr/A=";
    };

    nativeBuildInputs = [
        cmake
        ninja
    ];

    buildInputs = with pkgs; [
        libGL
        tacent
        xorg.libX11
        xorg.libxcb
    ];

    cmakeFlags = [
        "-DFETCHCONTENT_SOURCE_DIR_TACENT=${pkgs.poperigby.tacent.src}"
        "-DPACKAGE_NIX=True"
    ];

    installPhase = ''
        mkdir -p $out/bin
        cp tacentview $out/bin
        chmod +x $out/bin/tacentview
    '';

    meta = {
        description = "An image and texture viewer";
        homepage = "https://github.com/bluescan/tacentview";
        license = lib.licenses.isc;
        mainProgram = pname;
    };
}

This is for it’s depedency, Tacent:

{
    cmake,
    fetchFromGitHub,
    ninja,
    stdenv,
}:

stdenv.mkDerivation rec {
    pname = "tacent";
    version = "0.8.17";

    src = fetchFromGitHub {
        owner = "bluescan";
        repo = pname;
        rev = "8ea66e53db59876ff117c0b965b0745cf5ffcfdc";
        hash = "sha256-aTnFE/FqwtmHSvZjEJrcG1DEDbxJZHXIWqKi4SFBIWM=";
    };

    nativeBuildInputs = [
        cmake
        ninja
    ];
}

When I try to run it, it gives me this error:

Exe /nix/store/cjbd98in5afvwbj9ajsnhi9hxwlbpg8k-tacentview-1.0.44/bin/tacentview
Tacent View V 1.0.44
Tacent Library V 0.8.17
Dear ImGui V 1.89.2
GLFW V 3.3.2
For CLI Mode: tacentview --cli --help
LocInfo: staticDataDir : /Data/
LocInfo; ThumbCacheDir : /home/cassidy/.tacentview/Cache/
LocInfo: cfgFile       : /home/cassidy/.tacentview/Viewer.cfg
Glfw Error 65542: GLX: Failed to load GLX

Do I need to wrap it with the GLX path or something?

I would try to find examples in nixpkgs.

You need to patch the executable:

  postFixup = ''
    patchelf \
      --add-needed ${libGL}/lib/libGL.so.1 \
      $out/bin/tacentview
  '';
tacent.nix
{
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
  ninja,
}:

stdenv.mkDerivation rec {
  pname = "tacent";
  version = "0.8.17";

  src = fetchFromGitHub {
    owner = "bluescan";
    repo = pname;
    rev = "8ea66e53db59876ff117c0b965b0745cf5ffcfdc";
    hash = "sha256-aTnFE/FqwtmHSvZjEJrcG1DEDbxJZHXIWqKi4SFBIWM=";
  };

  postPatch = ''
    cp -r . $source
  '';

  outputs = [
    "out"
    "source"
  ];

  nativeBuildInputs = [
    cmake
    ninja
  ];

  meta = {
    description = "C++ library implementing linear algebra, text and file IO, UTF-N conversions, containers, image loading/saving, image quantization/filtering, command-line parsing, etc";
    homepage = "https://github.com/bluescan/tacent";
    license = lib.licenses.isc;
  };
}
tacentview.nix
{
  lib,
  stdenv,
  fetchFromGitHub,
  patchelf,
  cmake,
  ninja,
  libGL,
  tacent,
  xorg,
}:

stdenv.mkDerivation rec {
  pname = "tacentview";
  version = "1.0.44";

  src = fetchFromGitHub {
    owner = "bluescan";
    repo = pname;
    rev = "97defc4beec597978fc7df0f2be4ac1bbe9d5bd1";
    hash = "sha256-/nN9S3B1+OgdhwA7X2NHZRQzYMH1VA31S6HpG5sjr/A=";
  };

  nativeBuildInputs = [
    patchelf
    cmake
    ninja
  ];

  buildInputs = [
    libGL
    tacent
    xorg.libX11
    xorg.libxcb
  ];

  cmakeFlags = [
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_TACENT" "${tacent.source}")
    (lib.cmakeBool "PACKAGE_NIX" true)
  ];

  installPhase = ''
    runHook preInstall

    install -D tacentview -t $out/bin

    runHook postInstall
  '';

  postFixup = ''
    patchelf \
      --add-needed ${libGL}/lib/libGL.so.1 \
      $out/bin/tacentview
  '';

  meta = {
    description = "An image and texture viewer";
    homepage = "https://github.com/bluescan/tacentview";
    license = lib.licenses.isc;
    mainProgram = pname;
  };
}

Perfect, thank you. Wonder why I didn’t see other packages doing this. Guess I didn’t look hard enough?

1 Like