Vulkan not supported by glfw on Intel UHD Graphics

here is my flake

{
  description = "C Template";

  inputs = {
    nixpkgs.url = "nixpkgs";
    systems.url = "github:nix-systems/x86_64-linux";
    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.systems.follows = "systems";
    };
  };

  outputs =
    { self
    , nixpkgs
    , flake-utils
    , ...
    }:
    # For more information about the C/C++ infrastructure in nixpkgs: https://nixos.wiki/wiki/C
    flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = nixpkgs.legacyPackages.${system};
      pname = "engine";
      version = "0.0.1";
      src = ./.;
      buildInputs = with pkgs; [
        # add library dependencies here i.e.
        #zlib
        # Tipp: you can use `nix-locate foo.h` to find the package that provides a header file, see https://github.com/nix-community/nix-index
        glfw-wayland
        vulkan-loader
        vulkan-headers
        vulkan-validation-layers
        glm
        libcxx
      ];
      nativeBuildInputs = with pkgs; [
        # add build dependencies here
        ## For mesonbuild:
        #meson ninja
        ## For cmake:
        #cmake
        ## For autotools:
        # autoconf-archive
        # autoreconfHook
        pkg-config
        # clangd language server.
        # Also start your IDE/editor from the shell provided by `nix develop` as the wrapped clangd from clang-tools needs environment variables set by the shell
        clang-tools
        vulkan-tools
      ];
    in
    {
      devShells.default = pkgs.mkShell
        {
          inherit buildInputs nativeBuildInputs;

          # You can use NIX_CFLAGS_COMPILE to set the default CFLAGS for the shell
          NIX_CFLAGS_COMPILE = "-g";
          # You can use NIX_LDFLAGS to set the default linker flags for the shell
          #NIX_LDFLAGS = "-L${lib.getLib zstd}/lib -lzstd";
        };

      # Pinned gcc: remain on gcc10 even after `nix flake update`
      #default = pkgs.mkShell.override { stdenv = pkgs.gcc10Stdenv; } {
      #  inherit buildInputs nativeBuildInputs;
      #};

      # Clang example:
      #default = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
      #  inherit buildInputs nativeBuildInputs;
      #};

      packages.default = pkgs.clangStdenv.mkDerivation {
        inherit buildInputs nativeBuildInputs pname version src;
      };
    });
}

here is my main.c

#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#include <stdio.h>

int main() {
        if (glfwVulkanSupported() == GLFW_FALSE) {
                fprintf(stderr, "vulkan not supported\n");
                return 1;
        }
        return 0;
}

which prints vulkan not supported when i run nix run

I have hardware.graphics.enable = true in my nixos config

here are the drivers I have installed

/run/opengl-driver/share/vulkan/icd.d/
ā”œā”€ā”€ dzn_icd.x86_64.json
ā”œā”€ā”€ intel_hasvk_icd.x86_64.json
ā”œā”€ā”€ intel_icd.x86_64.json
ā”œā”€ā”€ lvp_icd.x86_64.json
ā”œā”€ā”€ nouveau_icd.x86_64.json
ā”œā”€ā”€ radeon_icd.x86_64.json
ā””ā”€ā”€ virtio_icd.x86_64.json
āÆ nix edit -f "<nixpkgs>" glfw

No mention of vulkan. Custom flags for libGL and libEGL present: -DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY=...

āÆ nix build -f "<nixpkgs>" glfw.src
āÆ ag GLFW_VULKAN result/
result/docs/compile.md
364:of @b _GLFW_VULKAN_LIBRARY, @b _GLFW_EGL_LIBRARY, @b _GLFW_GLX_LIBRARY, @b

result/docs/news.md
287:### GLFW_VULKAN_STATIC CMake option has been removed {#vulkan_static_removed}

result/src/vulkan.c
56:#if defined(_GLFW_VULKAN_LIBRARY)
57:        _glfw.vk.handle = _glfwPlatformLoadModule(_GLFW_VULKAN_LIBRARY);

The compile.md describing the macros is rendered at GLFW: Compiling GLFW

A PR to Nixpkgs would be welcome

You can confirm the dynamic loading issues by running your example with LD_DEBUG=libs or using strace

I have added a pr for adding vulkan support to nixpkgs

2 Likes