Setting up vulkan for development

Hi, I’m trying to build a C++ project that uses Cmake and Vulkan.
The standard way to find vulkan across platform in Cmake is to include the find_vulkan.cmake module. Code for the module here.
From the source code, it works by checking the “VULKAN_SDK” environment variable and expects the lib/bin/include folders to be there.

I know I can use environment.variables.VULKAN_SDK = "directoryhere"; to set the environment variable, but the vulkan sdk is split over many packages. (vulkan-headers, vulkan-tools, vulkan-tools-lunarg, vulkan-loader, vulkan-validation-layers, vulkan-extension-layer, glslang)

For example, I want both vulkan-tools and vulkan-tools-lunarg (both have their own bin directory, so sadly a simple symlink wont work) to be in the one VULKAN_SDK directory.

I’m guessing the best thing to do would be to somehow copy all the packages into one directory, then set an environment variable there? This is just my second day using NixOS, I don’t know the best way to go about this.

Hi!
I’m not developing Vulkan applications, but I compile some from time to time.
Usually, I create a shell.nix for use with direnv and the great nix-direnv. The shell.nix lists the various needed packages in buildInputs and I add more of the Vulkan packages until it compiles. :wink:

I never needed to set VULKAN_SDK for anything. Take that with a grain of salt though, I also never tried to use the validation layers. If it doesn’t work out of the box, I could imagine to make it work with VK_LAYER_PATH somehow, that way it can be different folders.

Usually, my shell.nix looks somehow like this:

{ pkgs ? (import <nixpkgs> {}) }:
with pkgs;
mkShell {
  buildInputs = [
    # put packages here.
    glslang # or shaderc
    vulkan-headers
    vulkan-loader
    vulkan-validation-layers # maybe?
    # glm and whatnot …
  ];

  # If it doesn’t get picked up through nix magic
  VULKAN_SDK = "${vulkan-validation-layers}/share/vulkan/explicit_layer.d"
}

Thanks for posting this. It got me started recently. I’ve expanded it a little but I’m still not sure that the VULKAN_SDK path is correct. VK_LAYER_PATH is needed for vkconfig (otherwise it can’t find the chronos validation layer. I think the LD_LIBRARY_PATH is the one for apps finding the loader. I’m using .NET (F#) to test so that probably makes a difference. I used vulkan-headers for the SDK but vkconfig still doesn’t think there is an SDK installed. I’ve not tested it much but that’s where I’m at with it so far.

with import <nixpkgs> {};

mkShell {
  name = "dotnet";
  packages = [
    dotnet-sdk_8
    glfw
    freetype
    vulkan-headers
    vulkan-loader
    vulkan-validation-layers
    vulkan-tools        # vulkaninfo
    shaderc             # GLSL to SPIRV compiler - glslc
    renderdoc           # Graphics debugger
    tracy               # Graphics profiler
    vulkan-tools-lunarg # vkconfig
  ];

  buildInputs = with pkgs; [
    glfw
    freetype
  ];

  LD_LIBRARY_PATH="${glfw}/lib:${freetype}/lib:${vulkan-loader}/lib:${vulkan-validation-layers}/lib";
  VULKAN_SDK = "${vulkan-headers}";
  VK_LAYER_PATH = "${vulkan-validation-layers}/share/vulkan/explicit_layer.d";
}
1 Like