on iko/ghcjs-patch-master help sign in
Update cleanSourceWith based on the latest nixpkgs (#401)

commit06ea6ab854c710b4da993ba69325edaa22ace594 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateWed 15 Jan 2020, 13:56 (7 years ago) parent8e52ad6
15 files changed+54−22
lib/call-cabal-project-to-nix.nix+1−1 lib/clean-source-with.nix+47−2 overlays/haskell.nix+1−2 test/buildable/default.nix+1−2 test/cabal-22/default.nix+1−2 test/cabal-simple-prof/default.nix−1 test/cabal-simple/default.nix−1 test/cabal-source-repo/default.nix+1−2 test/cabal-sublib/default.nix−1 test/call-cabal-project-to-nix/default.nix+1−2 test/exe-only/default.nix−1 test/ghc-options/cabal.nix+1−2 test/project-flags/cabal.nix−1 test/setup-deps/default.nix−1 test/shell-for-setup-deps/default.nix−1
lib/call-cabal-project-to-nix.nix+1−1
@@ -1,5 +1,5 @@
11{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes, haskellLib, materialize }@defaults:
2−{ name ? null # optional name for better error messages
2+{ name ? src.name or (baseNameOf src) # optional name for better error messages
33, src
44, index-state ? null # Hackage index-state, eg. "2019-10-10T00:00:00Z"
55, index-sha256 ? null # The hash of the truncated hackage index-state
lib/clean-source-with.nix+47−2
@@ -3,7 +3,45 @@
33# It adds a subDir argument in a way that allows descending into a subdirectory
44# to compose with cleaning the source with a filter.
55{ lib }: rec {
6− cleanSourceWith = { filter ? path: type: true, src, subDir ? "" }:
6+
7+ # Like `builtins.filterSource`, except it will compose with itself,
8+ # allowing you to chain multiple calls together without any
9+ # intermediate copies being put in the nix store.
10+ #
11+ # lib.cleanSourceWith {
12+ # filter = f;
13+ # src = lib.cleanSourceWith {
14+ # filter = g;
15+ # src = ./.;
16+ # };
17+ # }
18+ # # Succeeds!
19+ #
20+ # builtins.filterSource f (builtins.filterSource g ./.)
21+ # # Fails!
22+ #
23+ # Parameters:
24+ #
25+ # src: A path or cleanSourceWith result to filter and/or rename.
26+ #
27+ # filter: A function (path -> type -> bool)
28+ # Optional with default value: constant true (include everything)
29+ # The function will be combined with the && operator such
30+ # that src.filter is called lazily.
31+ # For implementing a filter, see
32+ # https://nixos.org/nix/manual/#builtin-filterSource
33+ #
34+ # subDir: Descend into a subdirectory in a way that will compose.
35+ # It will be ase if `src = src + "/${subDir}` and filters
36+ # already applied to `src` will be respected.
37+ #
38+ # name: Optional name to use as part of the store path.
39+ # This defaults `src.name` or otherwise `baseNameOf src`.
40+ # We recommend setting `name` whenever `src` is syntactically `./.`.
41+ # Otherwise, you depend on `./.`'s name in the parent directory,
42+ # which can cause inconsistent names, defeating caching.
43+ #
44+ cleanSourceWith = { filter ? _path: _type: true, src, subDir ? "", name ? null }:
745 let
846 subDir' = if subDir == "" then "" else "/" + subDir;
947 # In case this is mixed with older versions of cleanSourceWith
@@ -22,14 +60,21 @@
2260 # Children only if both filters return true
2361 || (lib.strings.hasPrefix (origSrcSubDir + "/") path
2462 && (filter path type && parentFilter path type));
63+ name' = if name != null
64+ then name
65+ else (if isFiltered && src ? name
66+ then src.name
67+ else baseNameOf src)
68+ + (lib.optionalString (origSubDir != "") ("--" + baseNameOf origSubDir));
2569 in {
2670 inherit origSrc origSubDir origSrcSubDir;
2771 filter = filter';
28− outPath = (builtins.filterSource filter' origSrc) + origSubDir;
72+ outPath = (builtins.path { filter = filter'; path = origSrc; name = name'; }) + origSubDir;
2973 _isLibCleanSourceWithEx = true;
3074 # It is only safe for older cleanSourceWith to filter this one
3175 # if the we are still looking at the root of origSrc
3276 _isLibCleanSourceWith = origSubDir == "";
77+ name = name';
3378 };
3479
3580 pathHasContext = builtins.hasContext or (lib.hasPrefix builtins.storeDir);
overlays/haskell.nix+1−2
@@ -412,8 +412,7 @@ self: super: {
412412 # separately from the hsPkgs. The advantage is that the you can get the
413413 # plan-nix without building the project.
414414 cabalProject' =
415− { name ? null
416− , ... }@args:
415+ { ... }@args:
417416 let plan = importAndFilterProject (callCabalProjectToNix args);
418417 in let pkg-set = mkCabalProjectPkgSet
419418 { plan-pkgs = plan.pkgs;
test/buildable/default.nix+1−2
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "test-buildable";
87 index-state = "2019-04-30T00:00:00Z";
98 src = haskellLib.cleanGit { src = ../..; subDir = "test/buildable"; };
109 modules = [ { packages.buildable-test.flags.exclude-broken = true; } ];
@@ -33,4 +32,4 @@ in recurseIntoAttrs {
3332 inherit project packages;
3433 };
3534 };
36−}
35+}
test/cabal-22/default.nix+1−2
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "cabal-22";
87 src = haskellLib.cleanGit { src = ../..; subDir = "test/cabal-22"; };
98 };
109
@@ -63,4 +62,4 @@ in recurseIntoAttrs {
6362 inherit (packages) project;
6463 };
6564 };
66−}
65+}
test/cabal-simple-prof/default.nix−1
@@ -16,7 +16,6 @@ let
1616 ];
1717
1818 project = cabalProject' {
19− name = "cabal-simple-prof";
2019 src = haskellLib.cleanGit { src = ../..; subDir = "test/cabal-simple-prof"; };
2120 inherit modules;
2221 };
test/cabal-simple/default.nix−1
@@ -26,7 +26,6 @@ let
2626 ];
2727
2828 project = cabalProject' {
29− name = "cabal-simple";
3029 src = haskellLib.cleanGit { src = ../..; subDir = "test/cabal-simple"; };
3130 inherit modules;
3231 };
test/cabal-source-repo/default.nix+1−2
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "test-cabal-source-repo";
87 index-state = "2019-04-30T00:00:00Z";
98 src = ./.;
109 };
@@ -32,4 +31,4 @@ in recurseIntoAttrs {
3231 inherit pkgSet packages;
3332 };
3433 };
35−}
34+}
test/cabal-sublib/default.nix−1
@@ -14,7 +14,6 @@ let
1414
1515 # The ./pkgs.nix works for linux & darwin, but not for windows
1616 project = cabalProject' {
17− name = "cabal-sublib";
1817 src = haskellLib.cleanGit { src = ../..; subDir = "test/cabal-sublib"; };
1918 inherit modules;
2019 };
test/call-cabal-project-to-nix/default.nix+1−2
@@ -6,7 +6,6 @@ let
66 # This test could use cabalProject', but it does so that it
77 # tests using callCabalProjectToNix and importAndFilterProject
88 plan = (importAndFilterProject (callCabalProjectToNix {
9− name = "test-call-cabal-project-to-nix";
109 index-state = "2019-04-30T00:00:00Z";
1110 # reuse the cabal-simple test project
1211 src = ../cabal-simple;
@@ -39,4 +38,4 @@ in recurseIntoAttrs {
3938 inherit pkgSet packages;
4039 };
4140 };
42−}
41+}
test/exe-only/default.nix−1
@@ -5,7 +5,6 @@ with stdenv.lib;
55
66let
77 project = haskell-nix.cabalProject' {
8− name = "exe-only";
98 src = ./.;
109 };
1110
test/ghc-options/cabal.nix+1−2
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "test-ghc-options";
87 index-state = "2019-04-30T00:00:00Z";
98 src = ./.;
109 # TODO find a way to get the ghc-options into plan.json so we can use it in plan-to-nix
@@ -33,4 +32,4 @@ in recurseIntoAttrs {
3332 inherit project packages;
3433 };
3534 };
36−}
35+}
test/project-flags/cabal.nix−1
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "test-project-flags";
87 index-state = "2019-04-30T00:00:00Z";
98 src = ./.;
109 };
test/setup-deps/default.nix−1
@@ -5,7 +5,6 @@ with stdenv.lib;
55
66let
77 project = haskell-nix.cabalProject' {
8− name = "test-setup-deps";
98 src = pkgs.haskell-nix.haskellLib.cleanGit { src = ../..; subDir = "test/setup-deps"; };
109 modules = [{
1110 # Package has no exposed modules which causes
test/shell-for-setup-deps/default.nix−1
@@ -4,7 +4,6 @@ with stdenv.lib;
44
55let
66 project = cabalProject' {
7− name = "test-shell-for-setup-deps";
87 src = ./.;
98 modules = [{
109 # Package has no exposed modules which causes