@@ -30,13 +30,14 @@ in
30 # An alternative to adding `--sha256` comments into the
30 # An alternative to adding `--sha256` comments into the
31 # cabal.project file:
31 # cabal.project file:
32 # sha256map =
32 # sha256map =
33+ # { # For a `source-repository-package` use the `location` and `tag` as the key
33− # { "https://github.com/jgm/pandoc-citeproc"."0.17"
34+ # "https://github.com/jgm/pandoc-citeproc"."0.17"
34− # = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q"; };
35+ # = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q";
35−, lookupSha256 ?
36+ # # For a `repository` use the `url` as the key
36− if sha256map != null
37+ # "https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/bfc363b9f879c360e0a0460ec0c18ec87222ec32"
37− then { location, tag, ...}: sha256map."${location}"."${tag}"
38+ # = "sha256-g9xGgJqYmiczjxjQ5JOiK5KUUps+9+nlNGI/0SpSOpg=";
39−, extra-hackage-tarballs ? []
40+, extra-hackage-tarballs ? {}
40, source-repo-override ? {} # Cabal seems to behave incoherently when
41, source-repo-override ? {} # Cabal seems to behave incoherently when
41 # two source-repository-package entries
42 # two source-repository-package entries
42 # provide the same packages, making it
43 # provide the same packages, making it
@@ -192,7 +193,7 @@ let
193 replaceSourceRepos = projectFile:
194 replaceSourceRepos = projectFile:
195− fetchRepo = fetchgit: repoData:
196+ fetchPackageRepo = fetchgit: repoData:
197 fetched =
198 fetched =
198 if repoData.sha256 != null
199 if repoData.sha256 != null
@@ -200,7 +201,7 @@ let
201 let drv = builtins.fetchGit { inherit (repoData) url ref; };
202 let drv = builtins.fetchGit { inherit (repoData) url ref; };
202 in __trace "WARNING: No sha256 found for source-repository-package ${repoData.url} ${repoData.ref} download may fail in restricted mode (hydra)"
203 in __trace "WARNING: No sha256 found for source-repository-package ${repoData.url} ${repoData.ref} download may fail in restricted mode (hydra)"
203− (__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a lookupSha256 argument"
204+ (__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a sha256map argument"
206 # Download the source-repository-package commit and add it to a minimal git
207 # Download the source-repository-package commit and add it to a minimal git
@@ -221,14 +222,13 @@ let
221 tag = "minimal";
222 tag = "minimal";
224− blocks = pkgs.lib.splitString "\nsource-repository-package\n" ("\n" + projectFile);
225+ # Parse the `source-repository-package` blocks
225− initialText = pkgs.lib.lists.take 1 blocks;
226+ sourceRepoPackageResult = pkgs.haskell-nix.haskellLib.parseSourceRepositoryPackages
226− repoBlocks = builtins.map (pkgs.haskell-nix.haskellLib.parseBlock cabalProjectFileName lookupSha256) (pkgs.lib.lists.drop 1 blocks);
227+ cabalProjectFileName sha256map source-repo-override projectFile;
227− overrideSourceRepo = sourceRepo: (source-repo-override.${sourceRepo.url} or (pkgs.lib.id)) sourceRepo;
228+
228− sourceRepoData = pkgs.lib.lists.map (x: overrideSourceRepo x.sourceRepo) repoBlocks;
229+ # Parse the `repository` blocks
229− otherText = pkgs.evalPackages.writeText "cabal.project" (pkgs.lib.strings.concatStringsSep "\n" (
230+ repoResult = pkgs.haskell-nix.haskellLib.parseRepositories
230− initialText
231+ cabalProjectFileName sha256map cabal-install nix-tools sourceRepoPackageResult.otherText;
231− ++ (builtins.map (x: x.otherText) repoBlocks)));
233 # we need the repository content twice:
233 # we need the repository content twice:
234 # * at eval time (below to build the fixed project file)
234 # * at eval time (below to build the fixed project file)
@@ -239,12 +239,13 @@ let
239 # on the target system would use, so that the derivation is unaffected
239 # on the target system would use, so that the derivation is unaffected
240 # and, say, a linux release build job can identify the derivation
240 # and, say, a linux release build job can identify the derivation
241 # as built by a darwin builder, and fetch it from a cache
241 # as built by a darwin builder, and fetch it from a cache
242− sourceReposEval = builtins.map (fetchRepo pkgs.evalPackages.fetchgit) sourceRepoData;
242+ sourceReposEval = builtins.map (fetchPackageRepo pkgs.evalPackages.fetchgit) sourceRepoPackageResult.sourceRepos;
243− sourceReposBuild = builtins.map (x: (fetchRepo pkgs.fetchgit x).fetched) sourceRepoData;
243+ sourceReposBuild = builtins.map (x: (fetchPackageRepo pkgs.fetchgit x).fetched) sourceRepoPackageResult.sourceRepos;
245 sourceRepos = sourceReposBuild;
245 sourceRepos = sourceReposBuild;
246+ inherit (repoResult) tarballs extra-hackages;
246 makeFixedProjectFile = ''
247 makeFixedProjectFile = ''
247− cp -f ${otherText} ./cabal.project
248+ cp -f ${pkgs.evalPackages.writeText "cabal.project" repoResult.updatedText} ./cabal.project
249 pkgs.lib.optionalString (builtins.length sourceReposEval != 0) (''
250 pkgs.lib.optionalString (builtins.length sourceReposEval != 0) (''
250 chmod +w -R ./cabal.project
251 chmod +w -R ./cabal.project
@@ -279,7 +280,7 @@ let
280 fixedProject =
281 fixedProject =
281 if rawCabalProject == null
282 if rawCabalProject == null
282− then { sourceRepos = []; makeFixedProjectFile = ""; replaceLocations = ""; }
283+ then { sourceRepos = []; tarballs = {}; extra-hackages = []; makeFixedProjectFile = ""; replaceLocations = ""; }
283 else replaceSourceRepos rawCabalProject;
284 else replaceSourceRepos rawCabalProject;
285 # The use of the actual GHC can cause significant problems:
286 # The use of the actual GHC can cause significant problems:
@@ -524,7 +525,8 @@ let
524 # some packages that will be excluded by `index-state-found`
525 # some packages that will be excluded by `index-state-found`
525 # which is used by cabal (cached-index-state >= index-state-found).
526 # which is used by cabal (cached-index-state >= index-state-found).
526 dotCabal {
527 dotCabal {
527− inherit cabal-install nix-tools extra-hackage-tarballs;
528+ inherit cabal-install nix-tools;
529+ extra-hackage-tarballs = fixedProject.tarballs // extra-hackage-tarballs;
528 index-state = cached-index-state;
530 index-state = cached-index-state;
529 sha256 = index-sha256-found;
531 sha256 = index-sha256-found;
@@ -610,5 +612,5 @@ in {
610 projectNix = plan-nix;
612 projectNix = plan-nix;
611 index-state = index-state-found;
613 index-state = index-state-found;
612 inherit src;
614 inherit src;
613− inherit (fixedProject) sourceRepos;
615+ inherit (fixedProject) sourceRepos extra-hackages;