nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 backendStdenv,
3 fetchzip,
4 finalAttrs,
5 lib,
6 runCommand,
7 stdenvNoCC,
8 writeShellApplication,
9}:
10let
11 older = lib.versionOlder finalAttrs.version;
12 atLeast = lib.versionAtLeast finalAttrs.version;
13in
14{
15 sample-data =
16 let
17 # Releases prior to 10.14.1 don't have any sample data available to them, so just use the 10.14.1 release's
18 # sample data.
19 sample-data_10_14_1 = {
20 url = "https://github.com/NVIDIA/TensorRT/releases/download/v10.14/tensorrt_sample_data_20251106.zip";
21 hash = "sha256-IA1pH8idtk/7FD1Tf0hKtyP7A5SW/2ugezyBRluG8yk=";
22 };
23 in
24 fetchzip (
25 if older "10.14.1" then
26 sample-data_10_14_1
27 else
28 lib.getAttr finalAttrs.version {
29 "10.14.1" = sample-data_10_14_1;
30 }
31 );
32
33 mkTester =
34 name: cmdArgs:
35 writeShellApplication {
36 name = finalAttrs.name + "-tester-" + name;
37 runtimeInputs = [ finalAttrs.finalPackage ];
38 text = ''
39 ${lib.toShellVar "cmdArgs" cmdArgs}
40 echo "running ''${cmdArgs[*]@Q}"
41 "''${cmdArgs[@]}"
42 '';
43 };
44
45 # TODO(@connorbaker): Add tests for trtexec.
46 testers =
47 let
48 mkTesters = lib.flip import {
49 inherit (finalAttrs.passthru) mkTester sample-data;
50 inherit
51 atLeast
52 backendStdenv
53 finalAttrs
54 lib
55 older
56 ;
57 };
58 in
59 # Filter out sets of testers which are completely empty (not available on this architecture, this version, etc.).
60 lib.filterAttrs (_: attrs: attrs != { }) (
61 # Construct all the testers from the filesystem.
62 lib.packagesFromDirectoryRecursive {
63 callPackage = path: _: mkTesters path;
64 directory = ./testers;
65 }
66 );
67
68 # Wrap each of the derivations in testers in a runCommand.
69 tests = lib.mapAttrsRecursiveCond (as: !(lib.isDerivation as)) (
70 path: drv:
71 runCommand (lib.replaceString "-tester-" "-test-" drv.name)
72 {
73 nativeBuildInputs = [ drv ];
74 requiredSystemFeatures = [ "cuda" ];
75 }
76 ''
77 set -euo pipefail
78 mkdir -p "$out"
79 "${lib.getExe drv}" | tee -a "$out/test.log" || {
80 nixErrorLog "command failed with exit code $?"
81 exit 1
82 }
83 ''
84 ) finalAttrs.passthru.testers;
85}