Skip to content

Instantly share code, notes, and snippets.

@ConnorBaker
Created January 10, 2026 07:58
Show Gist options
  • Select an option

  • Save ConnorBaker/909119743f7a041021d947efe3d95415 to your computer and use it in GitHub Desktop.

Select an option

Save ConnorBaker/909119743f7a041021d947efe3d95415 to your computer and use it in GitHub Desktop.
# To build tests:
# nix-eval-jobs --force-recurse ./tensorrt-samples.nix --select 'attrs: attrs.tests' | \
# jq -cr '.drvPath | select(.!=null) + "^*"' | \
# nix build --keep-going --no-link --print-out-paths --stdin --builders '' -L -j4
{
system ? "x86_64-linux",
cudaCapabilities ? [ "8.9" ],
cudaVersionComponents ? 2,
tensorrtVersionComponents ? 2,
}:
let
nixpkgs = builtins.getFlake "github:ConnorBaker/nixpkgs/a72215af73a72b6a58cbcda743a91ea917f8bc7f";
cuda-legacy = builtins.getFlake "github:nixos-cuda/cuda-legacy/e236996718689d028e52b9aece3a19a09ed9cdc5";
pkgs = import nixpkgs {
config =
{ pkgs, ... }:
{
allowUnfreePredicate = pkgs._cuda.lib.allowUnfreeCudaPredicate;
inherit cudaCapabilities;
cudaSupport = true;
};
localSystem = { inherit system; };
overlays = [ cuda-legacy.overlays.default ];
};
inherit (pkgs.lib)
attrNames
attrValues
filter
flip
listToAttrs
mapAttrs
mapCartesianProduct
optionalAttrs
versionAtLeast
versionOlder
groupBy'
;
inherit (pkgs) _cuda callPackage;
inherit (_cuda.lib)
dotsToUnderscores
selectManifests
trimComponents
;
# Groups by the newest N components
groupByNewestN =
let
# Returns the newest of two versions
newest = a: b: if versionOlder a b then b else a;
in
n: versions: groupBy' newest "0" (trimComponents n) versions;
mkCudaPackages =
manifestVersions:
callPackage _cuda.bootstrapData.cudaPackagesPath {
manifests = selectManifests manifestVersions;
};
all-tensorrt-samples = listToAttrs (
mapCartesianProduct
(
{ cuda, tensorrt }:
{
name = "cuda_${dotsToUnderscores cuda}_tensorrt_${dotsToUnderscores tensorrt}";
value =
let
cudaPackages = mkCudaPackages {
inherit cuda tensorrt;
};
in
optionalAttrs cudaPackages.tensorrt.meta.available cudaPackages.tensorrt-samples;
}
)
{
cuda =
let
# Only CUDA 11.8+ have cuda_profiler_api, which is required for the ONNX MNIST sample.
cuda118Plus = filter (flip versionAtLeast "11.8") (attrNames _cuda.manifests.cuda);
in
# Only use the latest of each minor release
attrValues (groupByNewestN cudaVersionComponents cuda118Plus);
# Use the latest of each patch release
tensorrt = attrValues (
groupByNewestN tensorrtVersionComponents (attrNames _cuda.manifests.tensorrt)
);
}
);
in
{
testers = mapAttrs (
_: tensorrt-samples: tensorrt-samples.passthru.testers or { }
) all-tensorrt-samples;
tests = mapAttrs (_: tensorrt-samples: tensorrt-samples.passthru.tests or { }) all-tensorrt-samples;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment