Fight Covid-19 with Folding@home and NixOS

Thanks for this! Additionally, if you want the client to shut down when you exit the nix-shell, there’s a --lifeline <pid> option that can be used, as in:

FAHClient --lifeline $$ &
1 Like

The team is growing. 197 CPUs!

image

4 Likes

EDIT: Following @zimbatm’s advice I got:

Based on missing support in WSL1 as I pointed out above I’m trying to build a qemu vm equipped with the fahclient, does that make any sense ?

What I have is two files, vm.nix and vm-config.nix:

#vm.nix
{ config, lib, pkgs, ... }:

with lib;

{
  imports =
    [ <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
      <nixpkgs/nixos/modules/profiles/clone-config.nix>
      ./vm-config.nix
    ];

  system.build.qemuvmImage = import <nixpkgs/nixos/lib/make-disk-image.nix> {
    inherit lib config;
    pkgs = import <nixpkgs/nixos> { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
    diskSize = 8192;
    format = "qcow2";
    configFile = pkgs.writeText "configuration.nix"
      ''
        {
          imports = [ <./machine-config.nix> ];
        }
      '';
    };
}
#vm-config.nix
{ pkgs, lib, ... }:

with lib;

{
  imports = [
    <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
#    (import "${builtins.fetchTarball https://github.com/zimbatm/nixpkgs/archive/foldingathome.tar.gz}")
  ];

  config = {
    installer.cloneConfig = true;
    fileSystems."/" = {
      device = "/dev/disk/by-label/nixos";
      fsType = "ext4";
      autoResize = true;
    };

    # Set VM disk size (in MB)
    virtualisation.diskSize = 1024 * 2048;

    boot.growPartition = true;
    boot.kernelParams = [ "console=ttyS0 boot.shell_on_fail" ];
    boot.loader.grub.device = "/dev/vda";
    boot.loader.timeout = 0;

    i18n.defaultLocale = "de_DE.UTF-8";
    time.timeZone = "Europe/Paris";

    nixpkgs.config.allowUnfree = true;
    nixpkgs.config.allowUnsupportedSystem = true;
    nixpkgs.config.system-features = [ "kvm" "nixos-test" ];

    services = {
      timesyncd.enable = lib.mkDefault true;
      openssh = {
        enable = true;
        permitRootLogin = "yes";
      };
      # TODO How does that compare to https://github.com/NixOS/nixpkgs/blob/nixos-19.09/nixos/modules/services/misc/folding-at-home.nix
      foldingathome = {
        enable = true;
        user = "foldingathome";
      };
    };

    environment.systemPackages = with pkgs; [
      fahviewer fahcontrol
    ];

    users.extraUsers.root.password = "";
    users.mutableUsers = false;

    users.users.root = {
      extraGroups = [ "wheel" ];
    };
  };
}

when I nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./vm.nix -I nixpkgs=channel:nixos-unstable-small and then ./result/bin/run-nixos-vm I get:

qemu-system-x86_64: CPU model ‘host’ requires KVM

Why is that ?

Just to be sure. We don’t have to set a project id right?

Try removing the foldingathome.tar.gz URL from the imports and use it as a nixpkgs channel instead:
nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./vm.nix -I nixpkgs=https://github.com/zimbatm/nixpkgs/archive/foldingathome.tar.gz

The team ID and user are only for reporting purposes and are optional. If you don’t set anything the FAHClient defaults are team ID 0 and user “Anonymous”.

2 Likes

Does this mean this architecture won’t work, or do I need to switch to unstable?

error: Package ‘folding-at-home-6.02’ in /nix/store/idkc96q3ff5snbz45b3qi1fyp6plcy6v-nixos-19.09-19.09.2255.68d2f8325c3/nixos-19.09/pkgs/misc/foldingathome/default.nix:32 is
not supported on ‘x86_64-linux’, refusing to evaluate.

1 Like

On what platform are you? The folding@home project only provides x86_64-linux binaries unfortunately. but your error message doesn’t make sense to me.

EDIT: it looks like you are using the old package.

The latest packaging is currently available in:

  • https://github.com/zimbatm/nixpkgs/archive/foldingathome.tar.gz
  • channel:nixos-unstable-small

I get a

qemu-system-x86_64: CPU model ‘host’ requires KVM

using unstable either (see my last post above) ?

Did you get any further with your approach ?

Some of the builds like the qemu image require the host to have KVM installed/available (which is not the case under WSL).

By the way, the important part is to contribute towards folding@home. If it’s too much hassle with NixOS then you can also consider downloading the the official client from over there: https://foldingathome.org/iamoneinamillion/ . If you are running on Windows it will be more efficient without the VM overhead.

1 Like

One thing that I didn’t know is that only GPU is contributing towards corona research. So if you are contributing only CPU, it won’t help with this project specifically. Sorry, my initial message wasn’t precise enough and misleading.

I found this repo that has more information on the subject:

3 Likes

That was not the case until NixOS 20.03 release, was it ? Using nixpkgs=channel:nixos-19.09-small (New constraint between Release 19.09 and 20.03 in package qemu?) qemu just worked.

It seems that the Rosetta@Home (part of BOINC) is also helping to fight COVID-19, and in that case CPU-only users can also contribute. It’s quite easy to use in NixOS as BOINC Manager is already packaged in nixpkgs.

For me, using the services.boinc.enable option was not enough, and I had to manually launch the client boinc_client, and then configure it using boincmgr.

I’ve seen a few tasks labeled COVID-19 go through.

4 Likes

Latest stats. 319 CPUs running! That’s pretty impressive.

Packet.com have donated 100 m1-xlarge instances for the project thanks to @grahamc’s involvement.

image

5 Likes

Just out of curiosity, what is the AMD GPU situation? I got the impression it would only work for Nvidia but looks like there is an opencl-mesa implementation that works with the AMDGPU driver. Will that all work with the latest version of the package in nixpkgs?

Warning for those trying this method: the client stores some data in $PWD/work (including the work units and some configuration I think), so I’d suggest creating some permanent directory just for Folding@home and always cding to it before running the client, both to make sure you don’t lose work units in random places in your disk, and also to avoid cluttering up whatever directory you happened to be in.

1 Like

This is how I got F@H running on my GeForce GTX 1080 Ti server running NixOS 19.03 (actually it was mostly @Infinisil):

{ config, lib, pkgs, ... }:
let
  pkgs_latest = import <nixpkgs_latest> { inherit (config.nixpkgs) config; };
in
{
  disabledModules = [
    "services/misc/folding-at-home.nix"
  ];

  imports = [ 
    <nixpkgs_latest/nixos/modules/services/computing/foldingathome/client.nix>
  ];

  services.foldingathome.enable = true;
  services.foldingathome.package = pkgs_latest.fahclient;

  # From https://github.com/lovesegfault/nix-config/blob/8dd6eedd08cebaf39dd70203ff9e51f4c14cb8ec/hardware/nvidia.nix
  systemd.services.nvidia-control-devices = {
    wantedBy = [ "multi-user.target" ];
    serviceConfig.ExecStart = "${config.boot.kernelPackages.nvidia_x11.bin}/bin/nvidia-smi";
  };

  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.opengl.enable = true;
}

Additionally, since F@H is regularly running of ouf work with such a surge of new donors in last days, I also installed rosetta@home that still has pending covid-19 related CPU work, by adding:

  services.boinc.enable = true;
  services.boinc.allowRemoteGuiRpc = true;

And then installing BOINC Manager locally on my laptop and connecting to it via SSH tunnel on port 31416. The connection password is stored in /var/lib/boinc/gui_rpc_auth.cfg .

Finally I created a NixOS team for rosetta too: NixOS (I’ll gladly defer administration of the team to a more senior nixos person)

I’ve had no luck completing GPU Work Units, the Status tab is properly detecting my GPU Slot (gpu:0:Hawaii [Radeon R9 200/300 Series]) but the System Info tab is showing OpenCL: Not detected: clGetPlatformIDs() returned -1001, plus such error logs are showing up when a WU is given to me: 14:48:38:ERROR:WU02:FS00:Failed to start core: OpenCL device matching slot 0 not found, try setting 'opencl-index' manually. I have set opencl-index to 1 but I will need to wait another WU to figure out if it works out.
Would love to hear how people got it working.

For an AMD RX580, I used the nixos-rocm overlay on nixos-unstable. Github page on nixos-rocm also covers most of this. Another solution I tried which did not work was attempting to install amdgpu-pro.

git clone https://github.com/nixos-rocm/nixos-rocm.git /etc/nixos/overlays/

in /etc/nixos/configuration.nix

nixpkgs.overlays = [ (import ./overlays/nixos-rocm)];
 
hardware.opengl = {
  enable = true;
  extraPackages = with pkgs; [
    rocm-opencl-icd
    rocminfo
    rocm-opencl-runtime
    rocr-ext
  ];
};

I also had to specify usage of gpu slot 1 in folding@home configuration, f@h did not auto-find it.

4 Likes

If anyone is running into issues getting assigned jobs, the Work Servers running out of jobs due to the spike in the number of F@H clients.
It seems the team is working on it.
https://foldingforum.org/viewtopic.php?f=24&t=32424

I created a PR that improves services.boinc so it should be easier to use.

After applying this PR every user that is member of the boinc group can configure the BOINC service via boincmgr -d /var/lib/boinc.

Let me know if this helps.

4 Likes