Skip to content

Commit

Permalink
Make package sources independent
Browse files Browse the repository at this point in the history
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 NixOS/nixpkgs#112083

As a workaround we may allow the filtering to be disabled entirely.
This could be implemented as a `packages.<name>.filteredSource`
option with a default, but for now that seems over-engineered.
  • Loading branch information
roberth committed Jan 18, 2023
1 parent 6a56fbd commit f36d122
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f36d122

Please sign in to comment.