Unverified Commit 810a5360 authored by Someone's avatar Someone Committed by GitHub
Browse files

programs.nix-required-mounts.presets.zluda.enable: init (#501095)

parents fd93d760 a8a1365d
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -67,6 +67,23 @@ let
    # TODO: Refactor `hardware.graphics` to ease referencing the closure
    # NOTE: A naive implementation may e.g. introduce a conditional infinite recursion (https://github.com/NixOS/nixpkgs/pull/488199)
    nvidia-gpu.unsafeFollowSymlinks = true;

    zluda = {
      onFeatures = [
        "cuda"
      ];
      paths = [
        pkgs.addDriverRunpath.driverLink
        "/dev/dri"
        "/dev/kfd"
        "/sys/devices/virtual/kfd"
        # As per https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
        # 226 is the major ID for "Direct Rendering Infrastructure (DRI)" devices
        "/sys/dev/char/226:*"
      ]
      ++ config.hardware.graphics.extraPackages;
      unsafeFollowSymlinks = true;
    };
  };
in
{
@@ -82,6 +99,16 @@ in
      You may extend or override the exposed paths via the
      `programs.nix-required-mounts.allowedPatterns.nvidia-gpu.paths` option.
    '';

    presets.zluda.enable = lib.mkEnableOption ''
      Same as `programs.nix-required-mounts.presets.nvidia-gpu` but adds paths
      to the sandbox that are needed for running CUDA applications on top of
      the ZLUDA translation layer combined with AMD GPUs.

      You may extend or override the exposed paths via the
      `programs.nix-required-mounts.allowedPatterns.zluda.paths` option.
    '';

    allowedPatterns =
      with lib.types;
      lib.mkOption {
@@ -122,6 +149,14 @@ in
          inherit (defaults) nvidia-gpu;
        };
      })
      (lib.mkIf cfg.presets.zluda.enable {
        hardware.graphics.enable = lib.mkDefault true;
        hardware.amdgpu.zluda.enable = lib.mkDefault true;
        nix.settings.system-features = cfg.allowedPatterns.zluda.onFeatures;
        programs.nix-required-mounts.allowedPatterns = {
          inherit (defaults) zluda;
        };
      })
    ]
  );
}
+32 −21
Original line number Diff line number Diff line
@@ -40,9 +40,12 @@ in
    };

    opencl.enable = lib.mkEnableOption "OpenCL support using ROCM runtime library";
    zluda.enable = lib.mkEnableOption "CUDA support using ZLUDA runtime library";
    zluda.package = lib.mkPackageOption pkgs "zluda" { };
  };

  config = {
  config = lib.mkMerge [
    {
      boot.kernelParams =
        lib.optionals cfg.legacySupport.enable [
          "amdgpu.si_support=1"
@@ -55,15 +58,23 @@ in
        ];

      boot.initrd.kernelModules = lib.optionals cfg.initrd.enable [ "amdgpu" ];

    hardware.graphics = lib.mkIf cfg.opencl.enable {
    }
    (lib.mkIf cfg.opencl.enable {
      hardware.graphics = {
        enable = lib.mkDefault true;
        extraPackages = [
          pkgs.rocmPackages.clr
          pkgs.rocmPackages.clr.icd
        ];
      };
    })
    (lib.mkIf cfg.zluda.enable {
      hardware.graphics = {
        enable = lib.mkDefault true;
        extraPackages = [ cfg.zluda.package ];
      };
    })
  ];

  meta = {
    maintainers = with lib.maintainers; [ johnrtitor ];