@@ -5,21 +5,26 @@
6 * see also `call-cabal-project-to-nix`!
6 * see also `call-cabal-project-to-nix`!
8−{ runCommand, nix-tools, pkgs, mkCacheFile, materialize }:
8+{ runCommand, nix-tools, pkgs, mkCacheFile, materialize, haskellLib }:
9{ name ? src.name or null # optional name for better error messages
9{ name ? src.name or null # optional name for better error messages
11−, stackYaml ? null
11+, stackYaml ? "stack.yaml"
12, ignorePackageYaml ? false
12, ignorePackageYaml ? false
13, cache ? null
13, cache ? null
14, stack-sha256 ? null
14, stack-sha256 ? null
15+, resolverSha256 ? null
15, materialized ? null # Location of a materialized copy of the nix files
16, materialized ? null # Location of a materialized copy of the nix files
16, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
17, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
20+ inherit (haskellLib.fetchResolver {
21+ inherit src stackYaml resolverSha256;
22+ }) resolver fetchedResolver;
19 subDir' = src.origSubDir or "";
24 subDir' = src.origSubDir or "";
20 stackToNixArgs = builtins.concatStringsSep " " [
25 stackToNixArgs = builtins.concatStringsSep " " [
22− "--stack-yaml=${src}/${if stackYaml == null then "stack.yaml" else stackYaml}"
27+ "--stack-yaml=$SRC/${stackYaml}"
23 (if ignorePackageYaml then "--ignore-package-yaml" else "")
28 (if ignorePackageYaml then "--ignore-package-yaml" else "")
@@ -31,7 +36,7 @@ let
31 } // pkgs.lib.optionalAttrs (checkMaterialization != null) {
36 } // pkgs.lib.optionalAttrs (checkMaterialization != null) {
32 inherit checkMaterialization;
37 inherit checkMaterialization;
33 }) (runCommand (if name == null then "stack-to-nix-pkgs" else name + "-stack-to-nix-pkgs") {
38 }) (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 ];
35 # Needed or stack-to-nix will die on unicode inputs
40 # Needed or stack-to-nix will die on unicode inputs
36 LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
41 LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
37 LANG = "en_US.UTF-8";
42 LANG = "en_US.UTF-8";
@@ -39,15 +44,32 @@ let
39 preferLocalBuild = false;
44 preferLocalBuild = false;
41 mkdir -p $out${subDir'}
46 mkdir -p $out${subDir'}
48+ # If no resolver was fetched use the original stack.yaml
49+ if fetchedResolver == null
54+ # Replace the resolver path in the stack.yaml with the fetched version
58+ lndir -silent "${src}/." $SRC
60+ cp ${src}/${stackYaml} .
61+ chmod +w ${stackYaml}
62+ substituteInPlace ${stackYaml} --replace "${resolver}" "${fetchedResolver}"
42− '' + pkgs.lib.optionalString (cache != null) ''
64+ ${pkgs.lib.optionalString (cache != null) ''
43− cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
65+ cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
45 (cd $out${subDir'} && stack-to-nix ${stackToNixArgs})
67 (cd $out${subDir'} && stack-to-nix ${stackToNixArgs})
47 # We need to strip out any references to $src, as those won't
69 # We need to strip out any references to $src, as those won't
48 # be accessable in restricted mode.
70 # be accessable in restricted mode.
49 for nixf in $(find $out -name "*.nix" -type f); do
71 for nixf in $(find $out -name "*.nix" -type f); do
50− substituteInPlace $nixf --replace "${src}" "."
72+ substituteInPlace $nixf --replace "$SRC" "."
53 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
75 # move pkgs.nix to default.nix ensure we can just nix `import` the result.