# 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; }