about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIlan Joselevich <personal@ilanjoselevich.com>2024-05-25T20·04+0300
committerIlan Joselevich <personal@ilanjoselevich.com>2024-05-26T14·27+0000
commit3ebcf30b64038198f82db4ffd109f2a0af3e0cf7 (patch)
treefb77bb274590ade91e543b58c23cc4b013cdc536
parentedd93b19628e655c5903dd79393e6387b23b8168 (diff)
feat(tvix): filter src via lib.fileset r/8169
Previously changing any file (including default.nix or README.md) would
cause Nix to compute a different derivation path, resulting in needing
to (very often redundantly) rebuild the crate/package. With this change
you can expect less rebuilds.

Crate2nix currently does its own insufficient src filtering and it does
not expose an API to override the filtering, so instead I created a
function that we can use to override the src to have stricter filtering.

I implemented the filtering for all of the workspace members, if you
want to modify any of them, please read the lib.fileset docs
https://nixos.org/manual/nixpkgs/unstable/#sec-functions-library-fileset

Change-Id: I7ab5a0064a76938d14f7f65801be9f3a5c3bad04
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11714
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r--tvix/default.nix60
1 files changed, 60 insertions, 0 deletions
diff --git a/tvix/default.nix b/tvix/default.nix
index a3a4d35df60a..cffea7b95487 100644
--- a/tvix/default.nix
+++ b/tvix/default.nix
@@ -12,6 +12,25 @@ let
     SystemConfiguration
   ]);
 
+  # Filters the given source, only keeping files related to the build, preventing unnecessary rebuilds.
+  # Includes src in the root, all other .rs files, as well as Cargo.toml.
+  # Additional files to be included can be specified in extraFileset.
+  filterRustCrateSrc =
+    { root # The original src
+    , extraFileset ? null # Additional filesets to include (e.g. fileFilter for proto files)
+    }:
+    lib.fileset.toSource {
+      inherit root;
+      fileset = (lib.fileset.intersection
+        (lib.fileset.fromSource root) # We build our final fileset from the original src
+        (lib.fileset.unions ([
+          (root + "/src")
+          (lib.fileset.fileFilter (f: f.hasExt "rs") root)
+          # We assume that every Rust crate will at a minimum have .rs files and a Cargo.toml
+          (lib.fileset.fileFilter (f: f.name == "Cargo.toml") root)
+        ] ++ lib.optional (extraFileset != null) extraFileset)));
+    };
+
   # Load the crate2nix crate tree.
   crates = import ./Cargo.nix {
     inherit pkgs;
@@ -52,21 +71,34 @@ let
       };
 
       tvix-build = prev: {
+        src = filterRustCrateSrc rec {
+          root = prev.src.origSrc;
+          extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
+        };
         PROTO_ROOT = depot.tvix.build.protos.protos;
         nativeBuildInputs = protobufDep prev;
         buildInputs = darwinDeps;
       };
 
       tvix-castore = prev: {
+        src = filterRustCrateSrc rec {
+          root = prev.src.origSrc;
+          extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
+        };
         PROTO_ROOT = depot.tvix.castore.protos.protos;
         nativeBuildInputs = protobufDep prev;
       };
 
       tvix-cli = prev: {
+        src = filterRustCrateSrc { root = prev.src.origSrc; };
         buildInputs = prev.buildInputs or [ ] ++ darwinDeps;
       };
 
       tvix-store = prev: {
+        src = filterRustCrateSrc rec {
+          root = prev.src.origSrc;
+          extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
+        };
         PROTO_ROOT = depot.tvix.store.protos.protos;
         nativeBuildInputs = protobufDep prev;
         # fuse-backend-rs uses DiskArbitration framework to handle mount/unmount on Darwin
@@ -74,6 +106,34 @@ let
           ++ darwinDeps
           ++ lib.optional pkgs.stdenv.isDarwin pkgs.buildPackages.darwin.apple_sdk.frameworks.DiskArbitration;
       };
+
+      tvix-eval-builtin-macros = prev: {
+        src = filterRustCrateSrc { root = prev.src.origSrc; };
+      };
+
+      tvix-eval = prev: {
+        src = filterRustCrateSrc rec {
+          root = prev.src.origSrc;
+          extraFileset = (root + "/proptest-regressions");
+        };
+      };
+
+      tvix-glue = prev: {
+        src = filterRustCrateSrc {
+          root = prev.src.origSrc;
+        };
+      };
+
+      tvix-serde = prev: {
+        src = filterRustCrateSrc { root = prev.src.origSrc; };
+      };
+
+      nix-compat = prev: {
+        src = filterRustCrateSrc rec {
+          root = prev.src.origSrc;
+          extraFileset = (root + "/testdata");
+        };
+      };
     };
   };