@@ -101,21 +101,11 @@ let
101101 )
102102 else null;
103103
104− # Look for a index-state: field in the cabal.project file
105− parseIndexState = rawCabalProject:
106− let
107− indexState = pkgs.lib.lists.concatLists (
108− pkgs.lib.lists.filter (l: l != null)
109− (builtins.map (l: builtins.match "^index-state: *(.*)" l)
110− (pkgs.lib.splitString "\n" rawCabalProject)));
111− in
112− pkgs.lib.lists.head (indexState ++ [ null ]);
113−
114104 index-state-found = if index-state != null
115105 then index-state
116106 else
117107 let cabalProjectIndexState = if rawCabalProject != null
118− then parseIndexState rawCabalProject
108+ then pkgs.haskell-nix.haskellLib.parseIndexState rawCabalProject
119109 else null;
120110 in
121111 if cabalProjectIndexState != null
@@ -160,67 +150,15 @@ in
160150 then throw "Unknown index-state ${index-state-found}, the latest index-state I know about is ${pkgs.lib.last (builtins.attrNames index-state-hashes)}. You may need to update to a newer hackage.nix." else true);
161151
162152let
163− span = pred: list:
164− let n = pkgs.lib.lists.foldr (x: acc: if pred x then acc + 1 else 0) 0 list;
165− in { fst = pkgs.lib.lists.take n list; snd = pkgs.lib.lists.drop n list; };
166−
167− # Parse lines of a source-repository-package block
168− parseBlockLines = blockLines: builtins.listToAttrs (builtins.concatMap (s:
169− let pair = builtins.match " *([^:]*): *(.*)" s;
170− in pkgs.lib.optional (pair != null) (pkgs.lib.attrsets.nameValuePair
171− (builtins.head pair)
172− (builtins.elemAt pair 1))) blockLines);
173−
174− hashPath = path:
175− builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }
176− "echo -n $(${pkgs.nix}/bin/nix-hash --type sha256 --base32 ${path}) > $out");
177−
178− # Use pkgs.fetchgit if we have a sha256. Add comment like this
179− # --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z
180− # otherwise use __fetchGit.
181− fetchRepo = repo:
182− let sha256 = repo."--sha256" or (lookupSha256 repo);
183− in (if sha256 != null
184− then pkgs.evalPackages.fetchgit {
185− url = repo.location;
186− rev = repo.tag;
187− inherit sha256;
188− }
189− else
190− let drv = builtins.fetchGit {
191− url = repo.location;
192− ref = repo.tag;
193− };
194− in __trace "WARNING: No sha256 found for source-repository-package ${repo.location} ${repo.tag} download may fail in restricted mode (hydra)"
195− (__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a lookupSha256 argument"
196− drv)
197− ) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir);
198−
199− # Parse a source-repository-package and fetch it if has `type: git`
200− parseBlock = block:
201− let
202− x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
203− attrs = parseBlockLines x.fst;
204− in
205− if attrs."type" or "" != "git"
206− then {
207− sourceRepo = [];
208− otherText = "\nsource-repository-package\n" + block;
209− }
210− else {
211− sourceRepo = [ (fetchRepo attrs) ];
212− otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd;
213− };
214−
215153 # Deal with source-repository-packages in a way that will work in
216154 # restricted-eval mode (as long as a sha256 is included).
217155 # Replace source-repository-package blocks that have a sha256 with
218156 # packages: block containing nix sotre paths of the fetched repos.
219157 replaceSoureRepos = projectFile:
220158 let
221− blocks = pkgs.lib.splitString "\nsource-repository-package\n" projectFile;
159+ blocks = pkgs.lib.splitString "\nsource-repository-package\n" ("\n" + projectFile);
222160 initialText = pkgs.lib.lists.take 1 blocks;
223− repoBlocks = builtins.map parseBlock (pkgs.lib.lists.drop 1 blocks);
161+ repoBlocks = builtins.map (pkgs.haskell-nix.haskellLib.parseBlock cabalProjectFileName lookupSha256) (pkgs.lib.lists.drop 1 blocks);
224162 sourceRepos = pkgs.lib.lists.concatMap (x: x.sourceRepo) repoBlocks;
225163 otherText = pkgs.evalPackages.writeText "cabal.project" (pkgs.lib.strings.concatStringsSep "\n" (
226164 initialText