|
23 | 23 | }) resolver fetchedResolver;
|
24 | 24 |
|
25 | 25 | subDir' = src.origSubDir or "";
|
| 26 | + subDir = pkgs.lib.strings.removePrefix "/" subDir'; |
| 27 | + maybeCleanedSource = |
| 28 | + if haskellLib.canCleanSource src |
| 29 | + then (haskellLib.cleanSourceWith { |
| 30 | + name = if name != null then "${name}-root-cabal-files" else "source-root-cabal-files"; |
| 31 | + src = src.origSrc or src; |
| 32 | + filter = path: type: (!(src ? filter) || src.filter path type) && ( |
| 33 | + type == "directory" || |
| 34 | + pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ stackYaml ".cabal" "package.yaml" ]); }) |
| 35 | + else src.origSrc or src; |
| 36 | + |
26 | 37 | stackToNixArgs = builtins.concatStringsSep " " [
|
27 | 38 | "--full"
|
28 |
| - "--stack-yaml=$SRC/${stackYaml}" |
| 39 | + "--stack-yaml=$SRC${subDir'}/${stackYaml}" |
29 | 40 | (if ignorePackageYaml then "--ignore-package-yaml" else "")
|
30 | 41 | "-o ."
|
31 | 42 | ];
|
|
46 | 57 | preferLocalBuild = false;
|
47 | 58 | } (''
|
48 | 59 | mkdir -p $out${subDir'}
|
| 60 | + SRC=$(mktemp -d) |
| 61 | + cd $SRC |
| 62 | + # if maybeCleanedSource is empty, this means it's a new |
| 63 | + # project where the files haven't been added to the git |
| 64 | + # repo yet. We fail early and provide a useful error |
| 65 | + # message to prevent headaches (#290). |
| 66 | + if [ -z "$(ls -A ${maybeCleanedSource})" ]; then |
| 67 | + echo "cleaned source is empty. Did you forget to 'git add -A'?"; exit 1; |
| 68 | + fi |
| 69 | + lndir -silent "${maybeCleanedSource}/." $SRC |
| 70 | + ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"} |
49 | 71 | ${
|
50 |
| - # If no resolver was fetched use the original stack.yaml |
51 |
| - if fetchedResolver == null |
52 |
| - then '' |
53 |
| - SRC=${src} |
54 |
| - '' |
55 |
| - else |
| 72 | + # If a resolver was fetched use the it instead of the original stack.yaml |
| 73 | + pkgs.lib.optionalString (fetchedResolver != null) |
56 | 74 | # Replace the resolver path in the stack.yaml with the fetched version
|
57 | 75 | ''
|
58 |
| - SRC=$(mktemp -d) |
59 |
| - cd $SRC |
60 |
| - lndir -silent "${src}/." $SRC |
61 | 76 | rm ${stackYaml}
|
62 | 77 | cp ${src}/${stackYaml} .
|
63 | 78 | chmod +w ${stackYaml}
|
|
71 | 86 | # We need to strip out any references to $src, as those won't
|
72 | 87 | # be accessable in restricted mode.
|
73 | 88 | for nixf in $(find $out -name "*.nix" -type f); do
|
74 |
| - substituteInPlace $nixf --replace "$SRC" "." |
| 89 | + substituteInPlace $nixf --replace "$SRC${subDir'}" "." |
75 | 90 | done
|
76 | 91 |
|
77 | 92 | # move pkgs.nix to default.nix ensure we can just nix `import` the result.
|
|
0 commit comments