From da430f48723a3c728b8cb5ea630aba600105e568 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Sat, 9 Dec 2023 23:07:01 +0000 Subject: [PATCH] blender.gpuChecks: add unwrapped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An unwrapped check for `nix run`-ing on the host platform, instead of `nix build`-ing in the sandbox E.g.: ``` ❯ nix run -f ./. --arg config '{ cudaSupport = true; cudaCapabilities = [ "8.6" ]; cudaEnableForwardCompat = false; allowUnfree = true; }' -L blender.gpuChecks.cudaAvailable.unwrapped Blender 4.0.1 Read prefs: "/home/user/.config/blender/4.0/config/userpref.blend" CUDA is available Blender quit ❯ nix build -f ./. --arg config '{ cudaSupport = true; cudaCapabilities = [ "8.6" ]; cudaEnableForwardCompat = false; allowUnfree = true; }' -L blender.gpuChecks blender> Blender 4.0.1 blender> could not get a list of mounted file-systems blender> CUDA is available blender> Blender quit ``` --- pkgs/applications/misc/blender/default.nix | 10 +------ pkgs/applications/misc/blender/gpu-checks.nix | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 pkgs/applications/misc/blender/gpu-checks.nix diff --git a/pkgs/applications/misc/blender/default.nix b/pkgs/applications/misc/blender/default.nix index 284ee5778101..38f3e226d0ff 100644 --- a/pkgs/applications/misc/blender/default.nix +++ b/pkgs/applications/misc/blender/default.nix @@ -374,15 +374,7 @@ stdenv.mkDerivation (finalAttrs: { ''; }; - gpuChecks.cudaAvailable = { blenderWithCuda, runCommand }: runCommand - "blender-cuda-available" - { - nativeBuildInputs = [ blenderWithCuda ]; - requiredSystemFeatures = [ "cuda" ]; - } - '' - blender --background -noaudio --python-exit-code 1 --python ${./test-cuda.py} && touch $out - '' { }; + gpuChecks = callPackage ./gpu-checks.nix { }; }; meta = { diff --git a/pkgs/applications/misc/blender/gpu-checks.nix b/pkgs/applications/misc/blender/gpu-checks.nix new file mode 100644 index 000000000000..144cdeb968c4 --- /dev/null +++ b/pkgs/applications/misc/blender/gpu-checks.nix @@ -0,0 +1,29 @@ +{ + bash, + blender, + callPackage, + lib, + runCommand, + writeScriptBin, +}: + +let + blenderWithCuda = blender.override {cudaSupport = true;}; + name = "${blenderWithCuda.name}-check-cuda"; + unwrapped = writeScriptBin "${name}-unwrapped" '' + #!${lib.getExe bash} + ${lib.getExe blenderWithCuda} --background -noaudio --python-exit-code 1 --python ${./test-cuda.py} + ''; +in +{ + cudaAvailable = + runCommand name + { + nativeBuildInputs = [unwrapped]; + requiredSystemFeatures = ["cuda"]; + passthru = { + inherit unwrapped; + }; + } + "${name}-unwrapped && touch $out"; +}