haskell.nix/lib/clean-source-haskell.nix
Michael Peyton Jones 20b6629205
Drop 19.09 support (#947)
* Drop 19.09 support

This is a year old. NixOS doesn't even support the last stable release,
let alone the one before that.

Also cuts our CI size by a third, which is always nice.

* Remove 19.09 compatibility pieces
2020-11-27 10:34:31 +13:00

42 lines
1.3 KiB
Nix

# This is a source filter function which cleans common build products
# and files not needed to do a haskell build from a source directory.
#
# This can avoid unnecessary builds when these files change.
#
# It should be used with "pkgs.lib.cleanSourceWith". Alternatively,
# use the convenience function "cleanSourceHaskell".
#
{ lib }:
rec {
haskellSourceFilter = name: type:
let baseName = baseNameOf (toString name);
in ! (
# Filter out cabal build products.
baseName == "dist" || baseName == "dist-newstyle" ||
baseName == "cabal.project.local" ||
lib.hasPrefix ".ghc.environment" baseName ||
# Filter out stack build products.
lib.hasPrefix ".stack-work" baseName ||
# Filter out files left by ghci
lib.hasSuffix ".hi" baseName ||
# Filter out files generated by "hasktags"
baseName == "TAGS" || baseName == "tags" ||
# Filter out files which are commonly edited but don't
# affect the cabal build.
lib.hasSuffix ".nix" baseName
);
# Like pkgs.lib.cleanSource, but adds Haskell files to the filter.
cleanSourceHaskell = { src, name ? null }:
let
clean = lib.cleanSourceWith {
filter = haskellSourceFilter;
src = lib.cleanSource src;
inherit name;
};
in
if (builtins.typeOf src) == "path"
then clean else src;
}