@@ -16,6 +16,13 @@
16 # If the tests and benchmarks are not needed and they
16 # If the tests and benchmarks are not needed and they
17 # causes the wrong plan to be choosen, then we can use
17 # causes the wrong plan to be choosen, then we can use
18 # `configureArgs = "--disable-tests --disable-benchmarks";`
18 # `configureArgs = "--disable-tests --disable-benchmarks";`
19+, lookupSha256 ? _: null
20+ # Use the as an alternative to adding `--sha256` comments into the
21+ # cabal.project file:
22+ # lookupSha256 = repo:
23+ # { "https://github.com/jgm/pandoc-citeproc"."0.17"
24+ # = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q"; }
25+ # ."${repo.location}"."${repo.tag}";
21# cabal-install versions before 2.4 will generate insufficient plan information.
28# cabal-install versions before 2.4 will generate insufficient plan information.
@@ -94,21 +101,38 @@ let
94 (builtins.head pair)
101 (builtins.head pair)
95 (builtins.elemAt pair 1))) blockLines);
102 (builtins.elemAt pair 1))) blockLines);
97− fetchRepo = repo: (pkgs.fetchgit {
104+ hashPath = path:
98− url = repo.location;
105+ builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }
99− rev = repo.tag;
106+ "echo -n $(${pkgs.nix}/bin/nix-hash --type sha256 --base32 ${path}) > $out");
100− sha256 = repo."--sha256";
101− }) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir);
108+ # Use pkgs.fetchgit if we have a sha256. Add comment like this
109+ # --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z
110+ # otherwise use __fetchGit.
112+ let sha256 = repo."--sha256" or (lookupSha256 repo);
113+ in (if sha256 != null
114+ then pkgs.fetchgit {
115+ url = repo.location;
120+ let drv = builtins.fetchGit {
121+ url = repo.location;
124+ in __trace "WARNING: No sha256 found for source-repository-package ${repo.location} ${repo.tag} download may fail in restricted mode (hydra)"
125+ (__trace "Consider adding `--sha256: ${hashPath drv}` to the cabal.project file or passing in a lookupSha256 argument"
127+ ) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir);
103− # Parse a source-repository-package and fetch it if it containts
129+ # Parse a source-repository-package and fetch it if has `type: git`
104− # a line of the form
105− # --shar256: <<SHA256>>
106 parseBlock = block:
130 parseBlock = block:
108 x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
132 x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
109 attrs = parseBlockLines x.fst;
133 attrs = parseBlockLines x.fst;
111− if attrs."--sha256" or "" == ""
135+ if attrs."type" or "" != "git"
113 sourceRepo = [];
137 sourceRepo = [];
114 otherText = "\nsource-repository-package\n" + block;
138 otherText = "\nsource-repository-package\n" + block;