add implementation.md

This commit is contained in:
milahu 2022-04-25 18:51:48 +02:00 committed by GitHub
parent 64e8c51860
commit 8b19e7b14e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

51
implementation.md Normal file
View file

@ -0,0 +1,51 @@
## File resolution
`mach-nix` uses [nix-pypi-fetcher](https://github.com/DavHau/nix-pypi-fetcher) to translate package versions to URLs and hashes.
For example, the declaration "package pillow + version 9.1.0 + python 3.9 + linux" resolves to
```json
"Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl": [
"gig6+ZwcOluh2kTGcpbVqtGfEcU1tVGlrlUyijF84zE=",
"cp39"
],
```
The wheel URL is constructed in [pypi-crawlers/src/crawl_wheel_deps.py](pypi-crawlers/src/crawl_wheel_deps.py)
```py
def construct_url(name, pyver, filename: str):
base_url = "https://files.pythonhosted.org/packages/"
return f"{base_url}{pyver}/{name[0]}/{name}/{filename}"
```
So in this example, the full URL would be
```
https://files.pythonhosted.org/packages/cp39/p/pillow/Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
```
Now `mach-nix` can call Nix's `fetchurl` like
```nix
builtins.fetchurl {
url = "https://files.pythonhosted.org/packages/cp39/p/pillow/Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl";
sha256 = "gig6+ZwcOluh2kTGcpbVqtGfEcU1tVGlrlUyijF84zE=";
}
```
... and Nix will download the wheel file to `/nix/store`
```console
$ unzip -l /nix/store/7gbbbrsqkw7f69axyh818abh9yw45fnb-Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | head
Archive: /nix/store/7gbbbrsqkw7f69axyh818abh9yw45fnb-Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Length Date Time Name
--------- ---------- ----- ----
0 04-01-2022 10:08 PIL/
0 04-01-2022 10:08 Pillow.libs/
0 04-01-2022 10:08 Pillow-9.1.0.dist-info/
7311 04-01-2022 10:08 PIL/PdfImagePlugin.py
141328 04-01-2022 10:08 PIL/_imagingcms.cpython-39-x86_64-linux-gnu.so
46872 04-01-2022 10:08 PIL/_imagingtk.cpython-39-x86_64-linux-gnu.so
1513 04-01-2022 10:08 PIL/GribStubImagePlugin.py
```