Skip to content

Commit 2f9b022

Browse files
authored
Release 3.0.0 (#159)
* fix non-python packages passed via packagesExtra * refactor examples and readme for 3.0.0 * add changelog for 3.0.0 * bump version to 3.0.0 and update nixpkgs and pypi-deps-db dependencies
1 parent 7215759 commit 2f9b022

File tree

9 files changed

+159
-44
lines changed

9 files changed

+159
-44
lines changed

Changelog.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
1+
# 3.0.0 (14 Oct 2020)
2+
flakes pypi gateway, R support, new output formats, more packages for python 3.5/3.6, improved providers nixpkgs/wheel
3+
4+
### IMPORTANT NOTICE
5+
The UI has been reworked. It is backward compatible with a few exceptions. Most importantly, when importing mach-nix, an attribute set must be passed. It can be empty. Example:
6+
```nix
7+
let
8+
mach-nix = import (builtins.fetchGit {
9+
url = "https://github.com/DavHau/mach-nix/";
10+
ref = "refs/tags/3.0.0";
11+
}) {
12+
# optionally bring your own nixpkgs
13+
# pkgs = import <nixpkgs> {};
14+
15+
# or specify the python version
16+
# python = "python38";
17+
};
18+
in
19+
...
20+
```
21+
22+
### Features
23+
- Flakes gateway to pypi. Get a shell with arbitrary python packages. Example:
24+
```shell
25+
nix develop github:davhau/mach-nix#shellWith.requests.tensorflow.aiohttp
26+
```
27+
- New output formats:
28+
* **mkDockerImage** -> produces layered docker image containing a python environment
29+
* **mkNixpkgs** -> returns nixpkgs which is conform to the given requirements
30+
* **mkOverlay** -> returns an overlay function to make nixpkgs conform to the given requirements
31+
* **mkPythonOverrides** -> produces pythonOverrides to make python conform to the given requirements.
32+
33+
- New functions **fetchPypiSdist** and **fetchPypiWheel**. Example:
34+
```
35+
mach-nix.buildPythonPackge {
36+
src = fetchPypiSdist "requests" "2.24.0"
37+
};
38+
```
39+
40+
- When using the mach-nix cmdline tool, the nixpkgs channel can now be picked via:
41+
```
42+
mach-nix env ./env -r requirements.txt --nixpkgs nixos-20.09
43+
```
44+
45+
- R support (experimental): R packages can be passed via `packagesExtra`. Mach-nix will setup rpy2 accordingly. See [usage example](https://github.com/DavHau/mach-nix/blob/master/examples.md#r-and-python).
46+
47+
- Non-python packages can be passed via `packagesExtra` to include them into the environment.
48+
49+
50+
### Improvements
51+
- rework the logic for inheriting dependencies from nixpkgs
52+
- fixes.nix: allow alternative mod function signature with more arguments:
53+
`key-to-override.mod = pySelf: oldAttrs: oldVal: ...;`
54+
- allow derivations passed as `src` argument to buildPythonPackage
55+
- stop inheriting attribute names from nixpkgs, instead use normalized package names
56+
- rework the public API of mach-nix (largely downwards compatible)
57+
- add example on how to build aarch64 image containing a mach-nix env
58+
- tests are now enabled/disabled via global override which is more reliable
59+
- raise error if python version of any package in packagesExtra doesn't match to one of the environment
60+
61+
62+
### Fixes
63+
- nixpkgs packages with identical versions swallowed
64+
- pname/version null in buildPythonPackage
65+
- update dependency extractor to use "LANG=C.utf8" (increases available packages for python 3.5 and 3.6)
66+
- wheel provider picked wheels incompatible to python version
67+
- unwanted python buildInput inheritance when overriding nixpkgs
68+
- properly parse setup/install_requires if they are strings instead of lists
69+
70+
### Package Fixes
71+
- rpy2: sdist: remove conflicting patch for versions newer than 3.2.6
72+
- pytorch from nixpkgs was not detected as `torch`
73+
- pyqt5: fix for providers nixpkgs and wheel
74+
- httpx: remove patches
75+
76+
177
# 2.4.1 (21 Sep 2020)
278
bugfixes
379

Readme.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ Table of Contents
6161
You can either install mach-nix via pip or by using nix in case you already have the nix package manager installed.
6262
#### Installing via pip
6363
```shell
64-
pip install git+git://github.com/DavHau/mach-nix@2.4.1
64+
pip install git+git://github.com/DavHau/mach-nix@3.0.0
6565
```
6666
#### Installing via nix
6767
```shell
68-
nix-env -if https://github.com/DavHau/mach-nix/tarball/2.4.1 -A mach-nix
68+
nix-env -if https://github.com/DavHau/mach-nix/tarball/3.0.0 -A mach-nix
6969
```
7070

7171
---
7272
### Build a virtualenv-style python environment from a requirements.txt
7373
```bash
7474
mach-nix env ./env -r requirements.txt
75-
# mach-nix env -r ./requirements.txt -p 3.7 --nixpkgs '{ "rev": "c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38", "sha256": "1ak7jqx94fjhc68xh1lh35kh3w3ndbadprrb762qgvcfb8351x8v", }' "./env"
7675
```
7776
This will generate the python environment into `./env`. To activate it, execute:
7877
```bash
@@ -99,7 +98,7 @@ You can call mach-nix directly from a nix expression
9998
let
10099
mach-nix = import (builtins.fetchGit {
101100
url = "https://github.com/DavHau/mach-nix/";
102-
ref = "refs/tags/2.4.1";
101+
ref = "refs/tags/3.0.0";
103102
});
104103
in
105104
mach-nix.mkPython {
@@ -113,31 +112,35 @@ mach-nix.mkPython {
113112
find more examples under [./examples.md](/examples.md)
114113

115114
### Advanced
116-
Mach-nix can be fine tuned with additional arguments by importing it via `builtins.fetchGit`. Examples can be found in [./examples.md](/examples.md). There are 4 different methods which can be invoked:
115+
Mach-nix can be fine tuned with additional arguments. Examples can be found in [./examples.md](/examples.md).
116+
117+
Functions for building python environments:
117118
1. **mkPython** - builds a python environment for a given `requirements.txt`.
118-
1. **mkPythonShell** - returns the python environment suitable for nix-shell.
119+
1. **mkPythonShell** - builds a python environment suitable for nix-shell.
120+
1. **mkDockerImage** - builds a layered docker image containing a python environment.
121+
1. **mkNixpkgs** - returns nixpkgs which is conform to the given requirements.
122+
1. **mkOverlay** - returns an overlay function to make nixpkgs conform to the given requirements .
123+
1. **mkPythonOverrides** - produces pythonOverrides to make python conform to the given requirements.
124+
125+
Functions for building python packages or applications:
119126
1. **buildPythonPackage** - build a single python package from a source code while automatically detecting requirements.
120127
1. **buildPythonApplication** - same as **buildPythonPackage**, but package will not be importable by other python packages.
121128

122129
**buildPythonPackage** and **buildPythonApplication** accept the same arguments like their equally named partners in nixpkgs, plus the arguments of **mkPython**. If name/version/requirements arguments are omitted, mach-nix attempts to detect them automatically. See [./examples.md](/examples.md).
123130

124-
**mkPython** and **mkPythonShell** take exactly the following arguments:
131+
**mkPython** and all other **mk...** functions take exactly the following arguments:
125132

126133
#### Required Arguments:
127134
- **requirements** (string): Text content of a typical `requirements.txt`.
128135

129136
#### Optional Arguments:
130-
- **disable_checks** (bool): Disable tests wherever possible to decrease build time and failures due to nix incompatible tests
131-
- **extra_pkgs** (list) Include packages which are not available from pypi. Can contain tarball-URLs, paths, or `mach-nix.buildPythonPackage` calls.
132-
- **overrides_pre** (list): list of pythonOverrides to apply before the machnix overrides. Use this to include additional packages which can then be selected inside the `requirements`
133-
- **overrides_post** (list): list of pythonOverrides to apply after the machnix overrides. Use this to fixup packages.
134-
- **pkgs** (set): pass custom nixpkgs (20.03 or higher is required for wheel support). Base it on `mach-nix.nixpkgs.path` to avoid incompatibilities.
135137
- **providers** (set): define provider preferences (see examples below)
136-
- **pypi_deps_db_commit** (string): commit hash of a specific version of the dependency graph ([pypi-deps-db](https://github.com/DavHau/pypi-deps-db)).
137-
- **pypi_deps_db_sha256** (string): sha256 hash obtained via `nix-prefetch-url --unpack https://github.com/DavHau/pypi-deps-db/tarball/<pypi_deps_db_commit>`
138-
- **python** (set): select custom python version. To prevent compatibility issues, only take python packages from the nixpkgs version used by mach-nix. For example: `mach-nix.nixpkgs.python36`
139-
- **_provider_defaults** (set): builtin provider defaults. Disable them by passing {}
138+
- **packagesExtra** (list) Add extra packages. Can contain tarball-URLs or paths of python source code, packages built via `mach-nix.buildPythonPackage`, or R Packages.
140139
- **_** (set): use underscore argument to easily modify arbitrary attributes of packages. For example to add built inputs use `_.{package}.builtInputs.add = [...]`. Or to remove patches use `_.{package}.patches = [...]`.
140+
- **overridesPre** (list): (advanced) list of pythonOverrides to apply before the machnix overrides. Use this to include additional packages which can then be selected inside the `requirements`
141+
- **overridesPost** (list): (advanced) list of pythonOverrides to apply after the machnix overrides. Use this to fixup packages.
142+
- **tests** (bool): Whether to enable tests (default: false)
143+
- **_providerDefaults** (set): builtin provider defaults. Disable them by passing {}
141144

142145
#### Configure Providers
143146
**Providers** allow you to configure the origin for your packages on a granular basis.

examples.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,22 @@ This page contains basic and advanced examples for using mach-nix inside a nix e
3535
<!--te-->
3636

3737
### Import mach-nix
38-
(every mach-nix expression should begin like this)
38+
every mach-nix expression should begin like this:
3939
```nix
4040
let
4141
mach-nix = import (builtins.fetchGit {
4242
url = "https://github.com/DavHau/mach-nix/";
43-
ref = "refs/tags/2.4.1";
43+
ref = "refs/tags/3.0.0";
4444
}) {
4545
# optionally bring your own nixpkgs
4646
# pkgs = import <nixpkgs> {};
47+
48+
# optionally specify the python version
49+
# python = "python38";
50+
51+
# optionally update pypi data revision from https://github.com/DavHau/pypi-deps-db
52+
# pypiDataRev = "some_revision";
53+
# pypiDataSha256 = "some_sha256";
4754
};
4855
in
4956
...
@@ -57,20 +64,26 @@ mach-nix.mkPython { # replace with mkPythonShell if shell is wanted
5764
}
5865
```
5966

60-
#### Include packages from arbitrary sources.
61-
`extra_pkgs` accepts python packages built via `mach-nix.buildPythonPackage`. Alternatively, paths or URLs can be passed which are then automatically wrapped in a `mach-nix.buildPythonPackage` call.
67+
#### Include extra packages.
68+
`packagesExtra` accepts:
69+
- python packages built via `mach-nix.buildPythonPackage`.
70+
- R Packages from `nixpkgs.rPackages` (see R example further down)
71+
- python package source trees as paths or derivations
72+
- URLs pointing to a tarball archives containing a python source tree
6273
```nix
74+
...
6375
mach-nix.mkPython {
6476
requirements = builtins.readFile ./requirements.txt;
65-
extra_pkgs = [
77+
packagesExtra = [
6678
"https://github.com/psf/requests/tarball/2a7832b5b06d" # from tarball url
6779
./some/local/project # from local path
6880
mach-nix.buildPythonPackage { ... }; # from package
6981
];
7082
}
7183
```
72-
Alternatively, if requirements are not needed, extra_pkgs can be passed directly to mkPython
84+
Alternatively, if requirements are not needed, packagesExtra can be passed directly to mkPython
7385
```nix
86+
...
7487
mach-nix.mkPython [
7588
"https://github.com/psf/requests/tarball/2a7832b5b06d" # from tarball url
7689
./some/local/project # from local path
@@ -79,37 +92,42 @@ mach-nix.mkPython [
7992
```
8093

8194
### buildPythonPackage / buildPythonApplication
82-
These functions can be used to manually build individual python modules or applications. Those can either be used directly, or fed as `extra_pkgs` of `mkPython`.
95+
These functions can be used to manually build individual python modules or applications. Those can either be used directly, or fed as `packagesExtra` of `mkPython`.
8396
Whenever `requirements` are not explicitly specified, they will be extracted automatically from the packages setup.py/setup.cfg. The same goes for the `name` and `version`.
8497
#### Build python package from its source code
8598
```nix
99+
...
86100
mach-nix.buildPythonPackage /python-project-path
87101
```
88102

89103
#### buildPythonPackage from GitHub
90104
```nix
105+
...
91106
mach-nix.buildPythonPackage "https://github.com/psf/requests/tarball/2a7832b5b06d"
92107
```
93108

94109
#### buildPythonPackage from GitHub with extras
95110
```nix
111+
...
96112
mach-nix.buildPythonPackage {
97113
src = "https://github.com/psf/requests/tarball/2a7832b5b06d";
98114
extras = "socks";
99115
}
100116
```
101117

102118
#### buildPythonPackage from GitHub and add requirements
103-
Use `add_requirements` in case the auto detected requirements are incomplete
119+
Use `requirementsExtra` in case the auto detected requirements are incomplete
104120
```nix
121+
...
105122
mach-nix.buildPythonPackage {
106123
src = "https://github.com/psf/requests/tarball/2a7832b5b06d";
107-
add_requirements = "pytest";
124+
requirementsExtra = "pytest";
108125
}
109126
```
110127

111128
#### buildPythonPackage from GitHub (reproducible source)
112129
```nix
130+
...
113131
mach-nix.buildPythonPackage {
114132
src = builtins.fetchGit{
115133
url = "https://github.com/user/projectname";
@@ -122,6 +140,7 @@ mach-nix.buildPythonPackage {
122140
#### buildPythonPackage from GitHub (manual requirements)
123141
Use this if automatic requirements extraction doesn't work at all.
124142
```nix
143+
...
125144
mach-nix.buildPythonPackage {
126145
src = "https://github.com/psf/requests/tarball/2a7832b5b06d";
127146
requirements = ''
@@ -152,6 +171,7 @@ mach-nix.mkPython {
152171
### Example: add missing build inputs
153172
For example the package web2ldap depends on another python package `ldap0` which fails to build because of missing dependencies.
154173
```nix
174+
...
155175
with mach-nix.nixpkgs;
156176
mach-nix.mkPython {
157177
@@ -168,6 +188,7 @@ mach-nix.mkPython {
168188
`imagecodecs` is available via wheel, but if one wants to build it from source, dependencies will be missing since there is no nixpkgs candidate available.
169189
poetry2nix luckily maintains overrides for this package. They can be included into the mach-nix build like this.
170190
```nix
191+
...
171192
mach-nix.mkPython rec {
172193
173194
requirements = ''
@@ -181,7 +202,7 @@ mach-nix.mkPython rec {
181202
182203
# Import overrides from poetry2nix
183204
# Caution! Use poetry2nix overrides only in `overrides_post`, not `overrides_pre`.
184-
overrides_post = [
205+
overridesPost = [
185206
(
186207
import (builtins.fetchurl {
187208
url = "https://raw.githubusercontent.com/nix-community/poetry2nix/1cfaa4084d651d73af137866622e3d0699851008/overrides.nix";
@@ -197,6 +218,7 @@ mach-nix.mkPython rec {
197218
Tensorflow from pypi does not provide any hardware optimization support. To get a SSE/AVX/FMA enabled version, set the provider for tensorflow to `nixpkgs`.
198219

199220
```nix
221+
...
200222
mach-nix.mkPython {
201223
202224
requirements = ''
@@ -213,6 +235,7 @@ This only works if the restrictions in `requirements.txt` allow for the tensorfl
213235
### Tensorflow via wheel (newer versions, quicker builds)
214236
Install recent tensorflow via wheel
215237
```nix
238+
...
216239
mach-nix.mkPython {
217240
218241
requirements = ''
@@ -228,6 +251,7 @@ mach-nix.mkPython {
228251
### Recent PyTorch with nixpkgs dependencies, and custom python
229252
Recent pytorch version, Build dependencies from source
230253
```nix
254+
...
231255
mach-nix.mkPython rec {
232256
233257
requirements = ''
@@ -241,21 +265,17 @@ mach-nix.mkPython rec {
241265
# allow wheels only for torch
242266
torch = "wheel";
243267
};
244-
245-
# Select custom python version (Must be taken from pkgs with the overlay applied)
246-
python = mach-nix.nixpkgs.python36;
247268
}
248269
```
249270

250271
## JupyterLab
251272

252273
### Starting point for a geospatial environment
253274
```nix
275+
...
254276
let
255277
pyEnv = mach-nix.mkPython rec {
256278
257-
python = "python37";
258-
259279
requirements = ''
260280
jupyterlab
261281
geopandas
@@ -280,10 +300,11 @@ mkShell rec {
280300
```
281301

282302
## Docker
283-
For every python environment a docker image is available via the `dockerImage` attribute of the `mkPython` result
303+
Docker images can be built by using `mkDockerImage` instead of `mkPython`. It accepts the same arguments.
284304
### JupyterLab Docker Image
285305
Assuming the following expression under `./jupyter-docker.nix`:
286306
```nix
307+
...
287308
let
288309
image = mach-nix.mkDockerImage {
289310
requirements = ''
@@ -314,16 +335,17 @@ docker run --rm -it -p 8888:8888 -v $HOME:/mnt jupyterlab
314335

315336
## R and Python
316337
The following is an example for a Python environment mixed with R packages.
317-
R packages can be added via `extra_pkgs`.
318-
If mach-nix finds R packages inside `extra_pkgs`, it will automatically include `rpy2` and add the selected R packages to its buildInputs.
338+
R packages can be added via `packagesExtra`.
339+
If mach-nix finds R packages inside `packagesExtra`, it will automatically include `rpy2` and add the selected R packages to its buildInputs.
319340
To get a list of available R packages, execute: `echo "builtins.attrNames(import <nixpkgs> {}).rPackages" | nix repl`
320341

321342
```nix
343+
...
322344
mach-nix.mkPython {
323345
requirements = ''
324346
# some python requirements
325347
'';
326-
extra_pkgs = with mach-nix.rPackages; [
348+
packagesExtra = with mach-nix.rPackages; [
327349
data_table
328350
];
329351
}
@@ -340,6 +362,7 @@ For the SD-image, create a configuration.nix file which adds the mach-nix tool a
340362
let
341363
machNix = import (builtins.fetchGit {
342364
url = "https://github.com/DavHau/mach-nix/";
365+
ref = "refs/tags/put_version_here";
343366
}) { inherit pkgs; };
344367
345368
defaultPythonEnv = machNix.mkPython {

mach_nix/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.1
1+
3.0.0

mach_nix/nix/NIXPKGS.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "https://github.com/nixos/nixpkgs",
3-
"rev": "502845c3e31ef3de0e424f3fcb09217df2ce6df6",
4-
"date": "2020-09-26T09:12:52+02:00",
5-
"sha256": "0fcqpsy6y7dgn0y0wgpa56gsg0b0p8avlpjrd79fp4mp9bl18nda",
3+
"rev": "41c0f49681009ceb57a65b7cd7d4e6d605df712c",
4+
"date": "2020-10-07T08:10:38+02:00",
5+
"sha256": "0ahi76lb38fcnbzl40k53yjr5vcc75kqg0ddcw6bbc6ckz0z27kg",
66
"fetchSubmodules": false
77
}

0 commit comments

Comments
 (0)