@@ -1,4 +1,4 @@
1−{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes }:
1+{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes, haskellLib }:
22let defaultGhc = ghc;
33 defaultCabalInstall = cabal-install;
44in { index-state ? null, index-sha256 ? null, src, ghc ? defaultGhc,
@@ -10,19 +10,19 @@ assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0
1010 else true);
1111let
1212 maybeCleanedSource =
13− if pkgs.lib.canCleanSource src
14− then pkgs.lib.cleanSourceWith {
13+ if haskellLib.canCleanSource src
14+ then haskellLib.cleanSourceWith {
1515 inherit src;
1616 filter = path: type:
1717 type == "directory" ||
1818 pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]; }
1919 else src;
2020
21− # Using origSrc bypasses any cleanSourceWith so that it will work when
21+ # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
2222 # access to the store is restricted. If origSrc was already in the store
2323 # you can pass the project in as a string.
2424 rawCabalProject =
25− let origSrcDir = maybeCleanedSource.origSrc or maybeCleanedSource;
25+ let origSrcDir = maybeCleanedSource.origSrcSubDir or maybeCleanedSource;
2626 in if cabalProject != null
2727 then cabalProject
2828 else
@@ -81,7 +81,7 @@ let
8181 parseBlock = block:
8282 let
8383 x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
84− attrs = parseBlockLines x.fst;
84+ attrs = parseBlockLines x.fst;
8585 in
8686 if attrs."--sha256" or "" == ""
8787 then {
@@ -137,7 +137,7 @@ let
137137 }
138138 else replaceSoureRepos rawCabalProject;
139139
140− plan = runCommand "plan-to-nix-pkgs" {
140+ plan-nix = runCommand "plan-to-nix-pkgs" {
141141 nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ];
142142 } (''
143143 tmp=$(mktemp -d)
@@ -154,7 +154,8 @@ let
154154 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
155155 HOME=${dotCabal {
156156 index-state = index-state-found;
157− sha256 = index-sha256-found; }} cabal new-configure \
157+ sha256 = index-sha256-found;
158+ inherit cabal-install; }} cabal new-configure \
158159 --with-ghc=${ghc.targetPrefix}ghc \
159160 --with-ghc-pkg=${ghc.targetPrefix}ghc-pkg
160161
@@ -179,45 +180,9 @@ let
179180
180181 # run `plan-to-nix` in $out. This should produce files right there with the
181182 # proper relative paths.
182− (cd $out && plan-to-nix --plan-json $tmp/dist-newstyle/cache/plan.json -o .)
183+ (cd $out && plan-to-nix --full --plan-json $tmp/dist-newstyle/cache/plan.json -o .)
183184
184185 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
185186 mv $out/pkgs.nix $out/default.nix
186187 '');
187−in
188− # TODO: We really want this (symlinks) instead of copying the source over each and
189− # every time. However this will not work with sandboxed builds. They won't
190− # have access to `plan` or `src` paths. So while they will see all the
191− # links, they won't be able to read any of them.
192− #
193− # We should be able to fix this if we propagaed the build inputs properly.
194− # As we are `import`ing the produced nix-path here, we seem to be losing the
195− # dependencies though.
196− #
197− # I guess the end-result is that ifd's don't work well with symlinks.
198− #
199− # symlinkJoin {
200− # name = "plan-and-src";
201− # # todo: should we clean `src` to drop any .git, .nix, ... other irelevant files?
202− # buildInputs = [ plan src ];
203− # }
204− runCommand "plan-to-nix-pkgs-with-src" { nativeBuildInputs = [ pkgs.rsync ]; } (''
205− mkdir $out
206− # todo: should we clean `src` to drop any .git, .nix, ... other irelevant files?
207− rsync -a "${src}/" "$out/"
208− rsync -a ${plan}/ $out/
209− '' +
210− ( pkgs.lib.strings.concatStrings (
211− pkgs.lib.lists.zipListsWith (n: f: ''
212− mkdir -p $out/.source-repository-packages/${builtins.toString n}
213− rsync -a "${f}/" "$out/.source-repository-packages/${builtins.toString n}/"
214− '')
215− (pkgs.lib.lists.range 0 ((builtins.length fixedProject.sourceRepos) - 1))
216− fixedProject.sourceRepos
217− )
218− ) + ''
219− # Rsync will have made $out read only and that can cause problems when
220− # nix sandboxing is enabled (since it can prevent nix from moving the directory
221− # out of the chroot sandbox).
222− chmod +w $out
223− '')
188+in { projectNix = plan-nix; inherit src; inherit (fixedProject) sourceRepos; }