|
13 | 13 |
|
14 | 14 | lockFile = builtins.fromJSON (builtins.readFile lockFilePath); |
15 | 15 |
|
| 16 | + # Using custom fetchurl function here so that we can specify outputHashMode. |
| 17 | + # The hash we get from the lock file is using recursive ingestion even though |
| 18 | + # it’s not unpacked. So builtins.fetchurl and import <nix/fetchurl.nix> are |
| 19 | + # insufficient. |
| 20 | + # Note that this will be a derivation and not a path as fetchTarball is, |
| 21 | + # causing the hash of this input to be different on flake and non-flake evaluation. |
| 22 | + fetchurl = { url, sha256 }: |
| 23 | + derivation { |
| 24 | + builder = "builtin:fetchurl"; |
| 25 | + |
| 26 | + name = "source"; |
| 27 | + inherit url; |
| 28 | + |
| 29 | + outputHash = sha256; |
| 30 | + outputHashAlgo = "sha256"; |
| 31 | + outputHashMode = "recursive"; |
| 32 | + executable = false; |
| 33 | + unpack = false; |
| 34 | + |
| 35 | + system = "builtin"; |
| 36 | + |
| 37 | + # No need to double the amount of network traffic |
| 38 | + preferLocalBuild = true; |
| 39 | + |
| 40 | + impureEnvVars = [ |
| 41 | + # We borrow these environment variables from the caller to allow |
| 42 | + # easy proxy configuration. This is impure, but a fixed-output |
| 43 | + # derivation like fetchurl is allowed to do so since its result is |
| 44 | + # by definition pure. |
| 45 | + "http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy" |
| 46 | + ]; |
| 47 | + |
| 48 | + # To make "nix-prefetch-url" work. |
| 49 | + urls = [ url ]; |
| 50 | + }; |
| 51 | + |
16 | 52 | fetchTree = |
17 | 53 | info: |
18 | 54 | if info.type == "github" then |
|
44 | 80 | } else { |
45 | 81 | }) |
46 | 82 | else if info.type == "path" then |
47 | | - { outPath = builtins.path { path = info.path; }; |
| 83 | + |
| 84 | + { outPath = (builtins.path { |
| 85 | + path = if builtins.substring 0 1 info.path != "/" |
| 86 | + then src + ("/" + info.path) |
| 87 | + else info.path; } |
| 88 | + // (if info ? narHash then { sha256 = info.narHash; } else {}) |
| 89 | + ); |
48 | 90 | narHash = info.narHash; |
49 | 91 | } |
50 | 92 | else if info.type == "tarball" then |
|
53 | 95 | ({ inherit (info) url; } |
54 | 96 | // (if info ? narHash then { sha256 = info.narHash; } else {}) |
55 | 97 | ); |
| 98 | + narHash = info.narHash; |
56 | 99 | } |
57 | 100 | else if info.type == "gitlab" then |
58 | 101 | { inherit (info) rev narHash lastModified; |
|
63 | 106 | ); |
64 | 107 | shortRev = builtins.substring 0 7 info.rev; |
65 | 108 | } |
| 109 | + else if info.type == "file" then |
| 110 | + { outPath = |
| 111 | + if builtins.substring 0 7 info.url == "http://" || builtins.substring 0 8 info.url == "https://" then |
| 112 | + fetchurl |
| 113 | + ({ inherit (info) url; } |
| 114 | + // (if info ? narHash then { sha256 = info.narHash; } else {}) |
| 115 | + ) |
| 116 | + else if builtins.substring 0 7 info.url == "file://" then |
| 117 | + builtins.path |
| 118 | + ({ path = builtins.substring 7 (-1) info.url; } |
| 119 | + // (if info ? narHash then { sha256 = info.narHash; } else {}) |
| 120 | + ) |
| 121 | + else throw "can't support url scheme of flake input with url '${info.url}'"; |
| 122 | + narHash = info.narHash; |
| 123 | + } |
66 | 124 | else |
67 | | - # FIXME: add Mercurial, tarball inputs. |
| 125 | + # FIXME: add Mercurial input |
68 | 126 | throw "flake input has unsupported input type '${info.type}'"; |
69 | 127 |
|
70 | 128 | callFlake4 = flakeSrc: locks: |
|
167 | 225 |
|
168 | 226 | outputs = flake.outputs (inputs // { self = result; }); |
169 | 227 |
|
170 | | - result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake"; }; |
171 | | - |
| 228 | + result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; }; |
172 | 229 | in |
173 | 230 | if node.flake or true then |
174 | 231 | assert builtins.isFunction flake.outputs; |
|
190 | 247 | in |
191 | 248 | rec { |
192 | 249 | defaultNix = |
193 | | - (builtins.removeAttrs result ["__functor"]) |
| 250 | + result |
194 | 251 | // (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {}) |
195 | 252 | // (if result ? packages.${system}.default then { default = result.packages.${system}.default; } else {}); |
196 | 253 |
|
|
0 commit comments