@@ -54,20 +54,23 @@ in
5454
5555let
5656 ghc = ghc';
57+ subDir' = src.origSubDir or "";
58+ subDir = pkgs.lib.strings.removePrefix "/" subDir';
5759 maybeCleanedSource =
5860 if haskellLib.canCleanSource src
59− then haskellLib.cleanSourceWith {
60− inherit src;
61− filter = path: type:
62− type == "directory" ||
63− pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" ".freeze" "package.yaml" ]; }
64− else src;
61+ then (haskellLib.cleanSourceWith {
62+ name = src.name + "-root-cabal-files";
63+ src = src.origSrc;
64+ filter = path: type: src.filter path type && (
65+ type == "directory" ||
66+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" ".freeze" "package.yaml" ]); })
67+ else src.origSrc or src;
6568
6669 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
6770 # access to the store is restricted. If origSrc was already in the store
6871 # you can pass the project in as a string.
6972 rawCabalProject =
70− let origSrcDir = maybeCleanedSource.origSrcSubDir or maybeCleanedSource;
73+ let origSrcDir = (maybeCleanedSource.origSrcSubDir or maybeCleanedSource) + subDir';
7174 in if cabalProject != null
7275 then cabalProject
7376 else
@@ -321,12 +324,13 @@ let
321324 fi
322325 cp -r ${maybeCleanedSource}/* .
323326 chmod +w -R .
324− ${fixedProject.makeFixedProjectFile}
325327 # warning: this may not generate the proper cabal file.
326328 # hpack allows globbing, and turns that into module lists
327329 # without the source available (we cleaneSourceWith'd it),
328330 # this may not produce the right result.
329331 find . -name package.yaml -exec hpack "{}" \;
332+ ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
333+ ${fixedProject.makeFixedProjectFile}
330334 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
331335 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
332336 HOME=${dotCabal {
@@ -357,24 +361,24 @@ let
357361
358362 # make sure the path's in the plan.json are relative to $out instead of $tmp
359363 # this is necessary so that plan-to-nix relative path logic can work.
360− substituteInPlace $tmp/dist-newstyle/cache/plan.json --replace "$tmp" "$out"
364+ substituteInPlace $tmp${subDir'}/dist-newstyle/cache/plan.json --replace "$tmp" "$out"
361365
362366 # run `plan-to-nix` in $out. This should produce files right there with the
363367 # proper relative paths.
364− (cd $out && plan-to-nix --full --plan-json $tmp/dist-newstyle/cache/plan.json -o .)
368+ (cd $out${subDir'} && plan-to-nix --full --plan-json $tmp${subDir'}/dist-newstyle/cache/plan.json -o .)
365369
366370 # Remove the non nix files ".project" ".cabal" "package.yaml" files
367371 # as they should not be in the output hash (they may change slightly
368372 # without affecting the nix).
369− if [ -d $out/.source-repository-packages ]; then
370− chmod +w -R $out/.source-repository-packages
371− rm -rf $out/.source-repository-packages
373+ if [ -d $out${subDir'}/.source-repository-packages ]; then
374+ chmod +w -R $out${subDir'}/.source-repository-packages
375+ rm -rf $out${subDir'}/.source-repository-packages
372376 fi
373377 find $out \( -type f -or -type l \) ! -name '*.nix' -delete
374378 # Remove empty dirs
375379 find $out -type d -empty -delete
376380
377381 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
378− mv $out/pkgs.nix $out/default.nix
382+ mv $out${subDir'}/pkgs.nix $out${subDir'}/default.nix
379383 '');
380384in { projectNix = plan-nix; inherit src; inherit (fixedProject) sourceRepos; }