Can you do OpenCL developement on NixOS?

I have absolutely no idea what I’m doing so please feel free to call out any egregious misunderstandings on my part or if using OpenCL is a bad idea.

I want to write a program that uses OpenCL in C++, built with Meson. What packages do I need to include to get OpenCL to work? I’m using the following shell.nix:

{ pkgs ? import <nixpkgs> { } }:
with pkgs;
clangStdenv.mkDerivation {
  name = "env";
  buildInputs = [
  nativeBuildInputs = [

Other sources seem to indicate that you need to download your platform vendor’s SDK. This doesn’t mesh with my understanding that OpenCL is supposed to be for portable software that works on multiple machine configurations. At any rate, what do I need to include if I want to use them? I’ve tried the one that I have in my configuration.nix, intel-compute-runtime. That doesn’t seem to work.

To be specific, I’ve tried compiling a dummy program that uses OpenCL in two ways:

  • via clang directly. I added -lOpenCL to the invokation but I get a linker error.
  • via Meson. I added a dependency 'OpenCL' to the but it can’t discover it.

lucky-commit does it like nixpkgs/default.nix at e1fd6446cd69512eda9df7c31a5476cbf4b13b5c · NixOS/nixpkgs · GitHub

and add hardware.opengl.extraPackages = [ ];

That uses the Apple OpenCL framework (quote all-packages.nix inherit (darwin.apple_sdk.frameworks) OpenCL;) and I’m not on MacOS, and I’ve already added hardware.opengl.extraPackages on the machine.

And ocl-icd on Linux

1 Like