Running Folding@Home on NixOS with OpenCL support for AMD GPU

Running Folding@Home can be a geat way to help scientists around the world. The program can use spear CPU and GPU power to do scientific research. When I switched to NixOS it took some tinkering to get OpenCL working on my AND GPU so Folding@Home can use it in the background while my CPU is busy comping code and doing other stuff.

Installing ROCM and Folding@Home

The can be easly done by adding the folling values to your configuration.nix file and rebooting.

hardware.graphics = {
  enable = true;
  enable32Bit = lib.mkForce false;
  extraPackages = with pkgs; [
    rocmPackages.clr.icd
    rocmPackages.clr
    rocmPackages.rocminfo
    rocmPackages.rocm-runtime
  ];
};

systemd.tmpfiles.rules = [
  "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
];

environment.systemPackages = with pkgs; [
  fahclient
];

If you now try to run the fah-client and go to https://beta.foldingathome.org/ you can start folding on your CPU, but your GPU isn't showing up.

Running fah-client

If you start fah-client from the command line with the following command, it can find the OpenCL binaries and use them.

OCL_ICD_VENDORS=$(nix-build '<nixpkgs>' --no-out-link -A rocmPackages.clr.icd)/etc/OpenCL/vendors/ fah-client

If you go to the setting of your machine, there you can enable your GPU and start using it for scientific research.

A partial screenshot of folding at home where you can enable your GPU