From a8a1365dd293322ae60e6f6c7935d4db09ae6d09 Mon Sep 17 00:00:00 2001 From: Jacek Galowicz Date: Wed, 18 Mar 2026 19:44:31 +0100 Subject: [PATCH] programs.nix-required-mounts.presets.zluda.enable: init --- .../modules/programs/nix-required-mounts.nix | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/nixos/modules/programs/nix-required-mounts.nix b/nixos/modules/programs/nix-required-mounts.nix index f3e7a75646d0..d4de973c0401 100644 --- a/nixos/modules/programs/nix-required-mounts.nix +++ b/nixos/modules/programs/nix-required-mounts.nix @@ -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; + }; + }) ] ); }