on iko/ghcjs-patch-master help sign in
cleanSourceHaskell: Add more filters (#314)
2e4b4ebRodney Lorrimar
@@ -1,6 +1,12 @@
1This file contains a summary of changes to Haskell.nix and `nix-tools`
1This file contains a summary of changes to Haskell.nix and `nix-tools`
2that will impact users.
2that will impact users.
3
3
4+## November 18, 2019
5+ * Changed the `cleanSourceHaskell` to accept an attrset of `src` and
6+ (optional) `name` parameters. This allows you to keep the source
7+ derivation name constant, so that your builds are always
8+ cached. Usage of `cleanSourceHaskell` will need to be updated.
9+
4## October 12, 2019
10## October 12, 2019
5 * [`shellFor`](https://input-output-hk.github.io/haskell.nix/reference/library/#shellfor) no longer sets `CABAL_CONFIG` by default.
11 * [`shellFor`](https://input-output-hk.github.io/haskell.nix/reference/library/#shellfor) no longer sets `CABAL_CONFIG` by default.
6 This avoids surprising users, but means that Cabal may select a plan which is different to your Haskell.nix package set.
12 This avoids surprising users, but means that Cabal may select a plan which is different to your Haskell.nix package set.
docs/reference/library.md+34
@@ -241,6 +241,40 @@ The result is an attrset with the following values:
241
241
242## cleanSourceHaskell
242## cleanSourceHaskell
243
243
244+```
245+cleanSourceHaskell = { src, name ? null }: ...
246+```
247+
248+Filters a source tree removing common filenames that are not Haskell
249+build sources.
250+
251+This can avoid unecessary rebuilds when these files change.
252+
253+It's recommended to provide `name` so that the source derivation
254+remains constant regardless of how it was fetched.
255+
256+Example:
257+
258+```
259+src = pkgs.haskell-nix.cleanSourceHaskell {
260+ src = ./.;
261+ name = "myproject-src";
262+};
263+```
264+
265+## haskellSourceFilter
266+
267+```
268+haskellSourceFilter = name: type: ...
269+```
270+
271+This is a source filter function which cleans common build products
272+and files not needed to do a Haskell build from a source directory.
273+
274+It should be used with `pkgs.lib.cleanSourceWith`. Alternatively,
275+use the convenience function [`cleanSourceHaskell`](#cleansourcehaskell).
276+
277+
244## haskellLib
278## haskellLib
245
279
246Assorted functions for operating on [Haskell.nix][] data. This is
280Assorted functions for operating on [Haskell.nix][] data. This is
lib/clean-source-haskell.nix+54−24
@@ -1,25 +1,55 @@
1−# This function cleans common build products and files not needed to do a
1+# This is a source filter function which cleans common build products
2−# haskell build from a source directory.
2+# and files not needed to do a haskell build from a source directory.
3+#
3# This can avoid unecessary builds when these files change.
4# This can avoid unecessary builds when these files change.
4−# It has been copied from iohk-nix so that it can be used internally in
5+#
5−# haskell.nix and made available to projects that do not use iohk-nix.
6+# It should be used with "pkgs.lib.cleanSourceWith". Alternatively,
6−# The original version is here:
7+# use the convenience function "cleanSourceHaskell".
7−# https://github.com/input-output-hk/iohk-nix/blob/c01bbd4e0c55a4101e2078d24046e0b2a731f871/clean-source-haskell.nix
8+#
8−{ pkgs }: src:
9+{ lib }:
9− let lib = pkgs.lib;
10+
10− in if (builtins.typeOf src) == "path"
11+rec {
11− then lib.cleanSourceWith {
12+ haskellSourceFilter = name: type:
12− filter = with pkgs.stdenv;
13− name: type: let baseName = baseNameOf (toString name); in ! (
13+ let baseName = baseNameOf (toString name);
14+ in ! (
14− # Filter out cabal build products.
15+ # Filter out cabal build products.
15− baseName == "dist" || baseName == "dist-newstyle" ||
16+ baseName == "dist" || baseName == "dist-newstyle" ||
16− baseName == "cabal.project.local" ||
17+ baseName == "cabal.project.local" ||
17− lib.hasPrefix ".ghc.environment" baseName ||
18+ lib.hasPrefix ".ghc.environment" baseName ||
18− # Filter out stack build products.
19+ # Filter out stack build products.
19− lib.hasPrefix ".stack-work" baseName ||
20+ lib.hasPrefix ".stack-work" baseName ||
21+ # Filter out files left by ghci
22+ lib.hasSuffix ".hi" baseName ||
23+ # Filter out files generated by "hasktags"
24+ baseName == "TAGS" || baseName == "tags" ||
20− # Filter out files which are commonly edited but don't
25+ # Filter out files which are commonly edited but don't
21− # affect the cabal build.
26+ # affect the cabal build.
22− lib.hasSuffix ".nix" baseName
27+ lib.hasSuffix ".nix" baseName
23− );
28+ );
29+
30+ # Like pkgs.lib.cleanSource, but adds Haskell files to the filter.
31+ cleanSourceHaskell = { src, name ? null }:
32+ let
33+ clean = lib.cleanSourceWith {
34+ filter = haskellSourceFilter;
24− src = lib.cleanSource src;
35+ src = lib.cleanSource src;
25− } else src
36+ inherit name;
37+ };
38+ # Copy function from 19.09 for compatibility with 19.03.
39+ # Does require at least Nix 2.0.
40+ compat = let
41+ isFiltered = src ? _isLibCleanSourceWith;
42+ origSrc = if isFiltered then src.origSrc else src;
43+ filter' = name: type: haskellSourceFilter name type && lib.cleanSourceFilter name type;
44+ name' = if name != null then name else if isFiltered then src.name else baseNameOf src;
45+ in {
46+ inherit origSrc;
47+ filter = filter';
48+ outPath = builtins.path { filter = filter'; path = origSrc; name = name'; };
49+ _isLibCleanSourceWith = true;
50+ name = name';
51+ };
52+ in
53+ if (builtins.typeOf src) == "path"
54+ then (if lib.versionAtLeast lib.version "19.09" then clean else compat) else src;
55+}
nix-tools/default.nix+8−5
@@ -4,11 +4,14 @@
4, ... }@args:
4, ... }@args:
5
5
6let
6let
7− src = cleanSourceHaskell (fetchExternal {
7+ src = cleanSourceHaskell {
8+ src = fetchExternal {
8− name = "nix-tools-src";
9+ name = "nix-tools-src";
9− specJSON = ./nix-tools-src.json;
10+ specJSON = ./nix-tools-src.json;
10− override = "nix-tools-src";
11+ override = "nix-tools-src";
12+ };
11− });
13+ };
14+
12 # we need to patch Cabal, as its data directory logic is broken for component builds, which haskell.nix
15 # we need to patch Cabal, as its data directory logic is broken for component builds, which haskell.nix
13 # uses excessively. See issue https://github.com/haskell/cabal/issues/5862, and the fix for Cabal 3.0
16 # uses excessively. See issue https://github.com/haskell/cabal/issues/5862, and the fix for Cabal 3.0
14 # in https://github.com/haskell/cabal/pull/6055. We apply the haskell/cabal#6055 here.
17 # in https://github.com/haskell/cabal/pull/6055. We apply the haskell/cabal#6055 here.
overlays/haskell.nix+4−2
@@ -31,8 +31,10 @@ self: super: {
31 # overridden with NIX_PATH.
31 # overridden with NIX_PATH.
32 fetchExternal = import ../lib/fetch-external.nix;
32 fetchExternal = import ../lib/fetch-external.nix;
33
33
34− # Function for cleaning haskell source directories pulled from iohk-nix
34+ # Functions for cleaning Haskell source directories.
35− cleanSourceHaskell = import ../lib/clean-source-haskell.nix { pkgs = self; };
35+ inherit (import ../lib/clean-source-haskell.nix { inherit (self) lib; })
36+ haskellSourceFilter
37+ cleanSourceHaskell;
36
38
37 # All packages from Hackage as Nix expressions
39 # All packages from Hackage as Nix expressions
38 hackageSrc = fetchExternal {
40 hackageSrc = fetchExternal {