Skip to content

Commit 4d3f8db

Browse files
Add CUDA 13 support
Load the appropriate graphics modules and firmware and make nvidia-jetpack.cudaPackages_13 an alias to the upstream cudaPackages_13. Convergence is real! Co-Authored-By: Connor Baker <[email protected]>
1 parent 1675dc4 commit 4d3f8db

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

mk-overlay.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let
4444
in
4545
makeScope final.newScope (self: {
4646
inherit (sourceInfo) debs gitRepos;
47-
inherit jetpackMajorMinorPatchVersion l4tMajorMinorPatchVersion cudaMajorMinorVersion;
47+
inherit jetpackMajorMinorPatchVersion l4tMajorMinorPatchVersion cudaMajorMinorVersion cudaDriverMajorMinorVersion;
4848
inherit l4tAtLeast l4tOlder;
4949

5050
callPackages = callPackagesWith (final // self);
@@ -230,10 +230,13 @@ makeScope final.newScope (self: {
230230
]
231231
++ _cuda.extensions);
232232
in
233+
if final.lib.versionAtLeast cudaMajorMinorPatchVersion "13" then
234+
final."cudaPackages_${cudaLib.dotsToUnderscores cudaMajorMinorVersion}"
235+
else
233236
# NOTE: We must ensure the scope allows us to draw on the contents of nvidia-jetpack.
234-
makeScope pkgs'.nvidia-jetpack.newScope (
235-
extends composedExtensions passthruFunction
236-
);
237+
makeScope pkgs'.nvidia-jetpack.newScope (
238+
extends composedExtensions passthruFunction
239+
);
237240

238241
samples = makeScope self.newScope (finalSamples: {
239242
callPackages = callPackagesWith (self // finalSamples);

modules/default.nix

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ let
3636
};
3737

3838
jetpackAtLeast = lib.versionAtLeast cfg.majorVersion;
39+
40+
getDriverDebs = prefix: (lib.filter (drv: lib.hasPrefix prefix (drv.pname or "")) (lib.attrValues pkgs.nvidia-jetpack.driverDebs));
41+
nvidiaDriverFirmwareDebs = getDriverDebs "nvidia-firmware-";
3942
in
4043
{
4144
imports = [
@@ -226,8 +229,8 @@ in
226229
message = "JetPack NixOS 6 supports CUDA 12.4 (natively) - 12.9 (with `cuda_compat`): `pkgs.cudaPackages` has version ${cudaMajorMinorVersion}.";
227230
}
228231
{
229-
assertion = !cudaAtLeast "13.0";
230-
message = "JetPack NixOS does not support CUDA 13.0 or later: `pkgs.cudaPackages` has version ${cudaMajorMinorVersion}.";
232+
assertion = cfg.majorVersion == "7" -> cudaAtLeast "13.0";
233+
message = "JetPack NixOS 7 suppoers CUDA 13.0 (natively): `pkgs.cudaPackages` has version ${cudaMajorMinorVersion}.";
231234
}
232235
]
233236
)
@@ -274,8 +277,11 @@ in
274277
isGeneric = cfg.som == "generic";
275278
isXavier = lib.hasPrefix "xavier-" cfg.som;
276279
isOrin = lib.hasPrefix "orin-" cfg.som;
280+
isThor = lib.hasPrefix "thor-" cfg.som;
277281
in
278-
lib.optionals (isXavier || isGeneric) [ "7.2" ] ++ lib.optionals (isOrin || isGeneric) [ "8.7" ];
282+
lib.optionals (isXavier || isGeneric) [ "7.2" ] ++
283+
lib.optionals (isOrin || isGeneric) [ "8.7" ] ++
284+
lib.optionals isThor [ "11.0" ];
279285
});
280286

281287
hardware.nvidia-jetpack.console.args = lib.mkMerge [
@@ -356,7 +362,7 @@ in
356362
];
357363

358364
boot.kernelModules =
359-
[ "nvgpu" ]
365+
(if (jetpackAtLeast "7") then [ "nvidia-uvm" ] else [ "nvgpu" ])
360366
++ lib.optionals (cfg.modesetting.enable && checkValidSoms [ "xavier" ]) [ "tegra-udrm" ]
361367
++ lib.optionals (cfg.modesetting.enable && checkValidSoms [ "orin" ]) [ "nvidia-drm" ];
362368

@@ -365,6 +371,10 @@ in
365371
'' + lib.optionalString cfg.modesetting.enable ''
366372
options tegra-udrm modeset=1
367373
options nvidia-drm modeset=1 ${lib.optionalString (cfg.majorVersion == "6") "fbdev=1"}
374+
'' + lib.optionalString (jetpackAtLeast "7") ''
375+
# from L4T-Ubuntu /etc/modprobe.d/nvidia-unifiedgpudisp.conf
376+
options nvidia NVreg_RegistryDwords="RMExecuteDevinitOnPmu=0;RMEnableAcr=1;RmCePceMap=0xffffff20;RmCePceMap1=0xffffffff;RmCePceMap2=0xffffffff;RmCePceMap3=0xffffffff;" NVreg_TegraGpuPgMask=512
377+
softdep nvidia pre: governor_pod_scaling post: nvidia-uvm
368378
'';
369379

370380
boot.extraModulePackages =
@@ -382,7 +392,9 @@ in
382392
vpi-firmware # Optional, but needed for pva_auth_allowlist firmware file used by VPI2
383393
] ++ lib.optionals (l4tOlder "36") [
384394
l4t-xusb-firmware # usb firmware also present in linux-firmware package, but that package is huge and has much more than needed
385-
];
395+
] ++ lib.optionals (l4tAtLeast "38") (nvidiaDriverFirmwareDebs ++ [ l4t-firmware-openrm ]);
396+
397+
boot.blacklistedKernelModules = [ "nouveau" ];
386398

387399
hardware.deviceTree.enable = true;
388400
hardware.deviceTree.dtboBuildExtraIncludePaths = {

overlay.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ in
5252
{
5353
jetpackMajorMinorPatchVersion = "7.0";
5454
l4tMajorMinorPatchVersion = "38.2.1";
55-
cudaMajorMinorPatchVersion = "12.6.10"; #TODO
55+
cudaMajorMinorPatchVersion = "13.0.2";
5656

5757
cudaDriverMajorMinorVersion = "580.00";
5858

@@ -102,7 +102,9 @@ in
102102
if (redistSystem final.nvidia-jetpack5.cudaMajorMinorVersion) == "linux-aarch64" then
103103
final.cudaPackages_11_4
104104
else
105-
prev.cudaPackages_11;
105+
# note: cudaPackages_11 removed upstream cuda-legacy re-introduces package sets with major and minor versions but does not change or create aliases for major versions
106+
# default to cudaPackages_11 if it exists or 11.8 as that was the default
107+
prev.cudaPackages_11 or prev.cudaPackages_11_8;
106108

107109
cudaPackages_12_6 =
108110
if (redistSystem final.nvidia-jetpack6.cudaMajorMinorVersion) == "linux-aarch64" then

pkgs/l4t/default.nix

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
, autoPatchelfHook
99
, dpkg
1010
, expat
11+
, libgcc
1112
, libglvnd
1213
, egl-wayland
1314
, xorg
@@ -396,7 +397,12 @@ let
396397

397398
l4t-nvsci = buildFromDeb {
398399
name = "nvidia-l4t-nvsci";
399-
buildInputs = [ l4t-core ];
400+
buildInputs = [ l4t-core ] ++ lib.optionals (l4tAtLeast "38") [ l4t-adaruntime ];
401+
};
402+
403+
l4t-adaruntime = buildFromDeb {
404+
name = "nvidia-l4t-adaruntime";
405+
buildInputs = [ libgcc ];
400406
};
401407

402408
# Programmable Vision Accelerator
@@ -437,7 +443,7 @@ let
437443

438444
l4t-wayland = buildFromDeb {
439445
name = "nvidia-l4t-wayland";
440-
buildInputs = [ wayland ];
446+
buildInputs = [ wayland ] ++ lib.optionals (l4tAtLeast "38") [ l4t-core ];
441447
postPatch = ''
442448
sed -i -E "s#(libnvidia-egl-wayland)#$out/lib/\\1#" share/egl/egl_external_platform.d/nvidia_wayland.json
443449
'';
@@ -449,15 +455,41 @@ let
449455
meta.platforms = [ "aarch64-linux" "x86_64-linux" ];
450456
};
451457

458+
l4t-firmware-openrm = buildFromDeb {
459+
name = "nvidia-l4t-firmware-openrm";
460+
autoPatchelf = false;
461+
meta.platforms = [ "aarch64-linux" "x86_64-linux" ];
462+
};
463+
464+
l4t-nvml = buildFromDeb {
465+
name = "nvidia-l4t-nvml";
466+
buildInputs = [ l4t-core ];
467+
};
468+
452469
nvidia-smi = buildFromDeb {
453470
name = "nvidia-smi";
454471
src = debs.${defaultSomRepo}.nvidia-l4t-nvml.src;
455472
version = debs.${defaultSomRepo}.nvidia-l4t-nvml.version;
456473
buildInputs = [ l4t-core ];
457474
# nvidia-smi will dlopen libnvidia-ml.so.1
458-
appendRunpaths = [ "${placeholder "out"}/lib" ];
475+
appendRunpaths = [ "${placeholder "out"}/lib" "/run/opengl-driver/lib" ];
459476
};
460477

478+
findDriverDebNames = majorVersion: lib.filter (lib.hasSuffix "-${majorVersion}") (lib.attrNames debs.common);
479+
driverDebNames = findDriverDebNames (lib.versions.major cudaDriverMajorMinorVersion);
480+
driverDebs = lib.genAttrs driverDebNames (name: buildFromDeb {
481+
inherit name;
482+
repo = "common";
483+
484+
buildInputs = lib.attrByPath [ name ] [ ] {
485+
libnvidia-compute-580 = [ driverDebs.libnvidia-decode-580 libgcc ];
486+
libnvidia-decode-580 = [ xorg.libX11 xorg.libXext ];
487+
libnvidia-encode-580 = [ driverDebs.libnvidia-decode-580 ];
488+
libnvidia-fbc1-580 = [ xorg.libX11 xorg.libXext ];
489+
libnvidia-gl-580 = [ xorg.libX11 xorg.libXext libgcc driverDebs.libnvidia-gpucomp-580 ];
490+
};
491+
});
492+
461493
vpiMajorVersion = {
462494
"35" = "2";
463495
"36" = "3";
@@ -494,9 +526,10 @@ in
494526
inherit
495527
l4t-dla-compiler
496528
nvidia-smi
529+
l4t-nvml
497530
;
498531
} // lib.optionalAttrs (l4tOlder "38") {
499532
inherit l4t-xusb-firmware; # L4T 38+ uses upstream firmware
500533
} // lib.optionalAttrs (l4tAtLeast "38") {
501-
inherit l4t-bootloader-utils;
534+
inherit l4t-bootloader-utils l4t-adaruntime driverDebs l4t-firmware-openrm;
502535
}

0 commit comments

Comments
 (0)