@@ -54,20 +54,23 @@ in
56 ghc = ghc';
56 ghc = ghc';
57+ subDir' = src.origSubDir or "";
58+ subDir = pkgs.lib.strings.removePrefix "/" subDir';
57 maybeCleanedSource =
59 maybeCleanedSource =
58 if haskellLib.canCleanSource src
60 if haskellLib.canCleanSource src
59− then haskellLib.cleanSourceWith {
61+ then (haskellLib.cleanSourceWith {
60− inherit src;
62+ name = src.name + "-root-cabal-files";
61− filter = path: type:
64+ filter = path: type: src.filter path type && (
62− type == "directory" ||
65+ type == "directory" ||
63− pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" ".freeze" "package.yaml" ]; }
66+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" ".freeze" "package.yaml" ]); })
64− else src;
67+ else src.origSrc or src;
66 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
69 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
67 # access to the store is restricted. If origSrc was already in the store
70 # access to the store is restricted. If origSrc was already in the store
68 # you can pass the project in as a string.
71 # you can pass the project in as a string.
69 rawCabalProject =
72 rawCabalProject =
70− let origSrcDir = maybeCleanedSource.origSrcSubDir or maybeCleanedSource;
73+ let origSrcDir = (maybeCleanedSource.origSrcSubDir or maybeCleanedSource) + subDir';
71 in if cabalProject != null
74 in if cabalProject != null
72 then cabalProject
75 then cabalProject
@@ -321,12 +324,13 @@ let
322 cp -r ${maybeCleanedSource}/* .
325 cp -r ${maybeCleanedSource}/* .
323 chmod +w -R .
326 chmod +w -R .
324− ${fixedProject.makeFixedProjectFile}
325 # warning: this may not generate the proper cabal file.
327 # warning: this may not generate the proper cabal file.
326 # hpack allows globbing, and turns that into module lists
328 # hpack allows globbing, and turns that into module lists
327 # without the source available (we cleaneSourceWith'd it),
329 # without the source available (we cleaneSourceWith'd it),
328 # this may not produce the right result.
330 # this may not produce the right result.
329 find . -name package.yaml -exec hpack "{}" \;
331 find . -name package.yaml -exec hpack "{}" \;
332+ ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
333+ ${fixedProject.makeFixedProjectFile}
330 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
334 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
331 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
335 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
332 HOME=${dotCabal {
336 HOME=${dotCabal {
@@ -357,24 +361,24 @@ let
358 # make sure the path's in the plan.json are relative to $out instead of $tmp
362 # make sure the path's in the plan.json are relative to $out instead of $tmp
359 # this is necessary so that plan-to-nix relative path logic can work.
363 # 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"
362 # run `plan-to-nix` in $out. This should produce files right there with the
366 # run `plan-to-nix` in $out. This should produce files right there with the
363 # proper relative paths.
367 # 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 .)
366 # Remove the non nix files ".project" ".cabal" "package.yaml" files
370 # Remove the non nix files ".project" ".cabal" "package.yaml" files
367 # as they should not be in the output hash (they may change slightly
371 # as they should not be in the output hash (they may change slightly
368 # without affecting the nix).
372 # without affecting the nix).
369− if [ -d $out/.source-repository-packages ]; then
373+ if [ -d $out${subDir'}/.source-repository-packages ]; then
370− chmod +w -R $out/.source-repository-packages
374+ chmod +w -R $out${subDir'}/.source-repository-packages
371− rm -rf $out/.source-repository-packages
375+ rm -rf $out${subDir'}/.source-repository-packages
373 find $out \( -type f -or -type l \) ! -name '*.nix' -delete
377 find $out \( -type f -or -type l \) ! -name '*.nix' -delete
374 # Remove empty dirs
378 # Remove empty dirs
375 find $out -type d -empty -delete
379 find $out -type d -empty -delete
377 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
381 # 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
380in { projectNix = plan-nix; inherit src; inherit (fixedProject) sourceRepos; }
384in { projectNix = plan-nix; inherit src; inherit (fixedProject) sourceRepos; }