@@ -23,9 +23,20 @@ let
2323 }) resolver fetchedResolver;
2424
2525 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+
2637 stackToNixArgs = builtins.concatStringsSep " " [
2738 "--full"
28− "--stack-yaml=$SRC/${stackYaml}"
39+ "--stack-yaml=$SRC${subDir'}/${stackYaml}"
2940 (if ignorePackageYaml then "--ignore-package-yaml" else "")
3041 "-o ."
3142 ];
@@ -46,18 +57,22 @@ let
4657 preferLocalBuild = false;
4758 } (''
4859 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}"}
4971 ${
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)
5674 # Replace the resolver path in the stack.yaml with the fetched version
5775 ''
58− SRC=$(mktemp -d)
59− cd $SRC
60− lndir -silent "${src}/." $SRC
6176 rm ${stackYaml}
6277 cp ${src}/${stackYaml} .
6378 chmod +w ${stackYaml}
@@ -71,7 +86,7 @@ let
7186 # We need to strip out any references to $src, as those won't
7287 # be accessable in restricted mode.
7388 for nixf in $(find $out -name "*.nix" -type f); do
74− substituteInPlace $nixf --replace "$SRC" "."
89+ substituteInPlace $nixf --replace "$SRC${subDir'}" "."
7590 done
7691
7792 # move pkgs.nix to default.nix ensure we can just nix `import` the result.