From f36d122d0da0d334c006682846bca8dc791a6fa8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 18 Jan 2023 15:25:57 +0100 Subject: [PATCH] Make package sources independent This prevents unnecessary rebuilds of packages that haven't really changed, except for a hash that included irrelevant sources. By applying a trivial source filter, we create a new store path that only contains the subdirectory that the build cares about. This isn't 100% compatible with all projects, as some packages might "legitimately" depend on files outside of their own directory. We could support this by adding an option for sources to be unioned, but a source union function isn't available, _yet_. For progress, check https://github.com/NixOS/nixpkgs/pull/112083 As a workaround we may allow the filtering to be disabled entirely. This could be implemented as a `packages..filteredSource` option with a default, but for now that seems over-engineered. --- flake-module.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/flake-module.nix b/flake-module.nix index a23f9b7a..ab7e59e0 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -169,9 +169,18 @@ in localPackagesOverlay = self: _: let fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg)); + filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; }; in lib.mapAttrs - (name: value: fromSdist (self.callCabal2nix name value.root { })) + (name: value: + let + # callCabal2nix does not need a filtered source. It will + # only pick out the cabal and/or hpack file. + pkgProto = self.callCabal2nix name value.root { }; + pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto { + src = filterSrc name value.root; + }; + in fromSdist pkgFiltered) cfg.packages; finalOverlay = pkgs.lib.composeManyExtensions