@@ -23,9 +23,20 @@ let
23 }) resolver fetchedResolver;
23 }) resolver fetchedResolver;
25 subDir' = src.origSubDir or "";
25 subDir' = src.origSubDir or "";
26+ subDir = pkgs.lib.strings.removePrefix "/" subDir';
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;
26 stackToNixArgs = builtins.concatStringsSep " " [
37 stackToNixArgs = builtins.concatStringsSep " " [
28− "--stack-yaml=$SRC/${stackYaml}"
39+ "--stack-yaml=$SRC${subDir'}/${stackYaml}"
29 (if ignorePackageYaml then "--ignore-package-yaml" else "")
40 (if ignorePackageYaml then "--ignore-package-yaml" else "")
@@ -46,18 +57,22 @@ let
46 preferLocalBuild = false;
57 preferLocalBuild = false;
48 mkdir -p $out${subDir'}
59 mkdir -p $out${subDir'}
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;
69+ lndir -silent "${maybeCleanedSource}/." $SRC
70+ ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
50− # If no resolver was fetched use the original stack.yaml
72+ # If a resolver was fetched use the it instead of the original stack.yaml
51− if fetchedResolver == null
73+ pkgs.lib.optionalString (fetchedResolver != null)
56 # Replace the resolver path in the stack.yaml with the fetched version
74 # Replace the resolver path in the stack.yaml with the fetched version
60− lndir -silent "${src}/." $SRC
61 rm ${stackYaml}
76 rm ${stackYaml}
62 cp ${src}/${stackYaml} .
77 cp ${src}/${stackYaml} .
63 chmod +w ${stackYaml}
78 chmod +w ${stackYaml}
@@ -71,7 +86,7 @@ let
71 # We need to strip out any references to $src, as those won't
86 # We need to strip out any references to $src, as those won't
72 # be accessable in restricted mode.
87 # be accessable in restricted mode.
73 for nixf in $(find $out -name "*.nix" -type f); do
88 for nixf in $(find $out -name "*.nix" -type f); do
74− substituteInPlace $nixf --replace "$SRC" "."
89+ substituteInPlace $nixf --replace "$SRC${subDir'}" "."
77 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
92 # move pkgs.nix to default.nix ensure we can just nix `import` the result.