|
16 | 16 | # If the tests and benchmarks are not needed and they
|
17 | 17 | # causes the wrong plan to be choosen, then we can use
|
18 | 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}"; |
19 | 26 | , ...
|
20 | 27 | }@args:
|
21 | 28 | # cabal-install versions before 2.4 will generate insufficient plan information.
|
|
94 | 101 | (builtins.head pair)
|
95 | 102 | (builtins.elemAt pair 1))) blockLines);
|
96 | 103 |
|
97 |
| - fetchRepo = repo: (pkgs.fetchgit { |
98 |
| - url = repo.location; |
99 |
| - rev = repo.tag; |
100 |
| - sha256 = repo."--sha256"; |
101 |
| - }) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir); |
| 104 | + hashPath = path: |
| 105 | + builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; } |
| 106 | + "echo -n $(${pkgs.nix}/bin/nix-hash --type sha256 --base32 ${path}) > $out"); |
102 | 107 |
|
103 |
| - # Parse a source-repository-package and fetch it if it containts |
104 |
| - # a line of the form |
105 |
| - # --shar256: <<SHA256>> |
| 108 | + # Use pkgs.fetchgit if we have a sha256. Add comment like this |
| 109 | + # --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z |
| 110 | + # otherwise use __fetchGit. |
| 111 | + fetchRepo = repo: |
| 112 | + let sha256 = repo."--sha256" or (lookupSha256 repo); |
| 113 | + in (if sha256 != null |
| 114 | + then pkgs.fetchgit { |
| 115 | + url = repo.location; |
| 116 | + rev = repo.tag; |
| 117 | + inherit sha256; |
| 118 | + } |
| 119 | + else |
| 120 | + let drv = builtins.fetchGit { |
| 121 | + url = repo.location; |
| 122 | + ref = repo.tag; |
| 123 | + }; |
| 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" |
| 126 | + drv) |
| 127 | + ) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir); |
| 128 | + |
| 129 | + # Parse a source-repository-package and fetch it if has `type: git` |
106 | 130 | parseBlock = block:
|
107 | 131 | let
|
108 | 132 | x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
|
109 | 133 | attrs = parseBlockLines x.fst;
|
110 | 134 | in
|
111 |
| - if attrs."--sha256" or "" == "" |
| 135 | + if attrs."type" or "" != "git" |
112 | 136 | then {
|
113 | 137 | sourceRepo = [];
|
114 | 138 | otherText = "\nsource-repository-package\n" + block;
|
|
0 commit comments