@@ -5,21 +5,26 @@
55 *
66 * see also `call-cabal-project-to-nix`!
77 */
8−{ runCommand, nix-tools, pkgs, mkCacheFile, materialize }:
8+{ runCommand, nix-tools, pkgs, mkCacheFile, materialize, haskellLib }:
99{ name ? src.name or null # optional name for better error messages
1010, src
11−, stackYaml ? null
11+, stackYaml ? "stack.yaml"
1212, ignorePackageYaml ? false
1313, cache ? null
1414, stack-sha256 ? null
15+, resolverSha256 ? null
1516, materialized ? null # Location of a materialized copy of the nix files
1617, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
1718, ... }:
1819let
20+ inherit (haskellLib.fetchResolver {
21+ inherit src stackYaml resolverSha256;
22+ }) resolver fetchedResolver;
23+
1924 subDir' = src.origSubDir or "";
2025 stackToNixArgs = builtins.concatStringsSep " " [
2126 "--full"
22− "--stack-yaml=${src}/${if stackYaml == null then "stack.yaml" else stackYaml}"
27+ "--stack-yaml=$SRC/${stackYaml}"
2328 (if ignorePackageYaml then "--ignore-package-yaml" else "")
2429 "-o ."
2530 ];
@@ -31,7 +36,7 @@ let
3136 } // pkgs.lib.optionalAttrs (checkMaterialization != null) {
3237 inherit checkMaterialization;
3338 }) (runCommand (if name == null then "stack-to-nix-pkgs" else name + "-stack-to-nix-pkgs") {
34− nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git pkgs.cacert ];
39+ nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git pkgs.cacert pkgs.xorg.lndir ];
3540 # Needed or stack-to-nix will die on unicode inputs
3641 LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
3742 LANG = "en_US.UTF-8";
@@ -39,15 +44,32 @@ let
3944 preferLocalBuild = false;
4045 } (''
4146 mkdir -p $out${subDir'}
42− '' + pkgs.lib.optionalString (cache != null) ''
43− cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
44− '' + ''
47+ ${
48+ # If no resolver was fetched use the original stack.yaml
49+ if fetchedResolver == null
50+ then ''
51+ SRC=${src}
52+ ''
53+ else
54+ # Replace the resolver path in the stack.yaml with the fetched version
55+ ''
56+ SRC=$(mktemp -d)
57+ cd $SRC
58+ lndir -silent "${src}/." $SRC
59+ rm ${stackYaml}
60+ cp ${src}/${stackYaml} .
61+ chmod +w ${stackYaml}
62+ substituteInPlace ${stackYaml} --replace "${resolver}" "${fetchedResolver}"
63+ ''}
64+ ${pkgs.lib.optionalString (cache != null) ''
65+ cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
66+ ''}
4567 (cd $out${subDir'} && stack-to-nix ${stackToNixArgs})
4668
4769 # We need to strip out any references to $src, as those won't
4870 # be accessable in restricted mode.
4971 for nixf in $(find $out -name "*.nix" -type f); do
50− substituteInPlace $nixf --replace "${src}" "."
72+ substituteInPlace $nixf --replace "$SRC" "."
5173 done
5274
5375 # move pkgs.nix to default.nix ensure we can just nix `import` the result.