From 6125b85b0493db1aa8896e7f0f5784465cfec553 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 12 Jul 2024 01:44:40 +0300 Subject: [PATCH] nix: filter fossbeamer source before building (#9) This prevents unnecessary rebuilds in case non-rust stuff in the repo is changed. --- nix/overlay.nix | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nix/overlay.nix b/nix/overlay.nix index aa8ab2f..62ee795 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -2,6 +2,34 @@ self: pkgs: rec { fossbeamer_crates = import ../Cargo.nix { inherit pkgs; nixpkgs = pkgs.path; + + defaultCrateOverrides = + let + lib = pkgs.lib; + # 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. test fixtures) + }: + 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))); + }; + in + pkgs.defaultCrateOverrides // { + fossbeamer = prev: { + src = filterRustCrateSrc { root = prev.src.origSrc; }; + }; + }; }; fossbeamer = fossbeamer_crates.rootCrate.build.override {