From aa9d4c8bbcb93bab4eb72273382f6e80ebceb7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Thu, 3 Dec 2026 13:37:10 +0000 Subject: [PATCH] nix-builder: add a function `filterBundle` to generated flake outputs This function makes it possible to build a bundle for a subset of build sets, filtered by their build configs for example: ``` nix build "$(nix eval --raw .\#lib.x86_64-linux.filterBundle \ --apply 'filterBundle: (filterBundle (buildConfig: buildConfig.torchVersion == "2.14")).drvPath')^*" ``` --- nix-builder/lib/checks.nix | 31 +++++++++++++++++++ .../lib/flake-outputs/gen-flake-outputs.nix | 6 ++++ 2 files changed, 37 insertions(+) diff --git a/nix-builder/lib/checks.nix b/nix-builder/lib/checks.nix index 8647e581..58471871 100644 --- a/nix-builder/lib/checks.nix +++ b/nix-builder/lib/checks.nix @@ -23,6 +23,15 @@ let expectedTorchVersion = "2.13.0"; kernelBuildSetTorchVersions = lib.unique (map (buildSet: buildSet.torch.version) kernelBuildSets); + # `filterBundle` tests. + reluBoundsOutputs = genKernelFlakeOutputs { + inherit self; + path = ../tests/kernels/relu-torch-bounds; + }; + inherit (reluBoundsOutputs.lib.${stdenv.hostPlatform.system}) filterBundle; + fullBundleDrv = reluBoundsOutputs.packages.${stdenv.hostPlatform.system}.bundle.drvPath; + expectedTorchMajorMinor = lib.versions.majorMinor expectedTorchVersion; + badRegistrationCheck = testers.testBuildFailure' { drv = (genKernelFlakeOutputs { @@ -187,6 +196,28 @@ assert lib.assertMsg '' Torch minver/maxver filtering does not work: expected only build sets with Torch ${expectedTorchVersion}, got: ${lib.concatStringsSep ", " kernelBuildSetTorchVersions} ''; +assert lib.assertMsg ((filterBundle (_: true)).drvPath == fullBundleDrv) '' + filterBundle does not work: a filter that accepts everything should give the full bundle. +''; +assert lib.assertMsg ((filterBundle (_: false)).drvPath != fullBundleDrv) '' + filterBundle does not work: a filter that rejects everything should not give the full bundle. +''; +assert lib.assertMsg + ( + (filterBundle (buildConfig: buildConfig.torchVersion == expectedTorchMajorMinor)).drvPath + == fullBundleDrv + ) + '' + filterBundle does not work: filtering on Torch ${expectedTorchMajorMinor} should give the full bundle for relu-torch-bounds. + ''; +assert lib.assertMsg + ( + (filterBundle (buildConfig: buildConfig.torchVersion != expectedTorchMajorMinor)).drvPath + != fullBundleDrv + ) + '' + filterBundle does not work: filtering out Torch ${expectedTorchMajorMinor} should not give the full bundle for relu-torch-bounds. + ''; assert lib.assertMsg (torchVersionUtilsTestFailures == [ ]) '' torch-version-utils tests failed: ${builtins.toJSON torchVersionUtilsTestFailures} ''; diff --git a/nix-builder/lib/flake-outputs/gen-flake-outputs.nix b/nix-builder/lib/flake-outputs/gen-flake-outputs.nix index 2c062107..fd933735 100644 --- a/nix-builder/lib/flake-outputs/gen-flake-outputs.nix +++ b/nix-builder/lib/flake-outputs/gen-flake-outputs.nix @@ -119,6 +119,12 @@ in test = testShells.${bestVariant}; inherit testShells; }; + + # Filter build sets using a function useBuildSet :: buildConfig -> bool + # that gets the build set configuration. + lib.filterBundle = + useBuildSet: mkBundle (lib.filter (buildSet: useBuildSet buildSet.buildConfig) applicableBuildSets); + packages = let bundle = mkBundle applicableBuildSets;