-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
fetchdata and fetchmulti #19540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetchdata and fetchmulti #19540
Changes from all commits
b4afb21
589670a
a2e8015
1154479
f4e939e
3af379c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { fetchers }: | ||
|
|
||
| # One fetcher to rule them all. | ||
| # | ||
| # The input should only be pure nix data, no function calls. | ||
| # | ||
| # Example usage: | ||
| # | ||
| # fetchurl { | ||
| # url = "http://example.com/archive.tar.gz"; | ||
| # sha256 = "..."; | ||
| # }; | ||
| # | ||
| # Becomes: | ||
| # | ||
| # fetchdata { | ||
| # url = "http://example.com/archive.tar.gz"; | ||
| # sha256 = "..."; | ||
| # } | ||
| # | ||
| # If the data is not for fetchurl, it's possible to pass a "fetcher" | ||
| # attribute: | ||
| # | ||
| # fetchdata { | ||
| # fetcher = "fetchFromGitHub"; | ||
| # repo = "someone"; | ||
| # repo = "something"; | ||
| # rev = "v1.0"; | ||
| # sha256 = "..."; | ||
| # } | ||
| # | ||
| # Which means that the attributes can now be imported | ||
| # | ||
| # fetchdata (import ./source.nix); | ||
| # | ||
| # That's the whole point of this function. | ||
| # | ||
| { fetcher ? "fetchurl", ... }@attrs: | ||
|
||
| let | ||
| # TODO: add heuristic based on the input data instead | ||
| fetcher' = | ||
| fetchers."${fetcher}" or | ||
| (throw "fetcher of type `${fetcher}' not supported"); | ||
| attrs' = builtins.removeAttrs attrs ["fetcher"]; | ||
| in | ||
| fetcher' attrs' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { lib, fetchdata }: | ||
|
|
||
| # Similar to fetchdata but allows to switch on an attribute | ||
| # | ||
| # Example usage: | ||
| # | ||
| # fetchmulti stdenv.system { | ||
| # "x86_64-linux" = { | ||
| # url = "http://example.com/x86-linux.tar.gz"; | ||
| # sha256 = "..."; | ||
| # }; | ||
| # "i686-linux" = { | ||
| # url = "http://example.com/i686-linux.tar.gz"; | ||
| # sha256 = "..."; | ||
| # }; | ||
| # } | ||
| # | ||
| # All the urls are exposed on the `all' attribute which allows to run | ||
| # `nix-fetchetch-url -A mypackage.src.all` to calculate the checksums of the:q | ||
| # | ||
| # FIXME: right now nix-prefetch-url only work if one of the keys match the | ||
| # current plaform | ||
| # | ||
| key: data: | ||
| let | ||
| attrs = data."${key}" or (throw "`${key}' is not available as a source"); | ||
|
|
||
| # A list of all the fetcher urls | ||
| urls = lib.foldl | ||
| (sum: v: ((fetchdata v).urls or []) ++ sum) | ||
| [] | ||
| (builtins.attrValues data); | ||
| in | ||
| (fetchdata attrs) // { all = { inherit urls; }; } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whooaa! Cool!!