I’m working on docker-py. I have the following shell.nix:
with import <nixpkgs> {};
with python36Packages;
buildPythonPackage rec {
name = "docker-py";
src = ./. ;
propagatedBuildInputs = [ ipython ];
}
This works fine, except the tests require docker, which I cannot declare in buildPythonPackage. I think I need to do use mkShell so I came up with:
with import <nixpkgs> {};
with python36Packages;
let
docker-py-env = buildPythonPackage rec {
name = "docker-py";
src = ./. ;
propagatedBuildInputs = [ ipython ];
};
in mkShell {
buildInputs = [ docker-py-env docker ];
}
Unfortunately that fails with:
Executing pipInstallPhase
/build/docker-py/dist /build/docker-py
Processing ./docker-4.1.0.dev0-py2.py3-none-any.whl
Collecting websocket-client>=0.32.0 (from docker==4.1.0.dev0)
ERROR: Could not find a version that satisfies the requirement websocket-client>=0.32.0 (from docker==4.1.0.dev0) (from versions: none)
ERROR: No matching distribution found for websocket-client>=0.32.0 (from docker==4.1.0.dev0)
builder for '/nix/store/3drbvvmaclw907zf1x6429j1s3l9ciqz-python3.6-docker-py.drv' failed with exit code 1
error: build of '/nix/store/3drbvvmaclw907zf1x6429j1s3l9ciqz-python3.6-docker-py.drv', '/nix/store/n490dvn8n2q6jddjj3lip8vsxfbz86pn-python3.6-docker-4.0.2.drv' failed
[nix-shell:~/docker-py]$ make test
docker build -t docker-sdk-python -f tests/Dockerfile --build-arg PYTHON_VERSION=2.7 --build-arg APT_MIRROR .
make: docker: Command not found
make: *** [Makefile:11: build] Error 127
[nix-shell:~/docker-py]$ docker
The program ‘docker’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
nix-env -iA nixos.docker
nix-env -iA nixos.docker_18_09
[nix-shell:~/docker-py]$ ls /nix/store/mr50kaan2vs4gc40ymwncb2vci25aq7z-docker-19.03.2/
bin etc libexec share
[nix-shell:~/docker-py]$ echo $PATH
/run/user/1000/tmp.ejIpvcva1O/bin:/nix/store/lb3hli8d9536g45mndwfwyi6fpny0blh-bash-interactive-4.4-p23/bin:/nix/store/c8qshsnmy5d9xk3nxj2xy9xc4isnc7ni-python3
-3.6.9/bin:/nix/store/ib0912x9z6qmxjj0kgk70v804bfhqvyw-python3.6-setuptools-41.2.0/bin:/nix/store/c8qshsnmy5d9xk3nxj2xy9xc4isnc7ni-python3-3.6.9/bin:/nix/stor
e/1m37n3cd92r734rw852izzsr2m05baj4-python3.6-wheel-0.33.6/bin:/nix/store/id8diq0fd3z94ridhqqr8bqy77q4xndy-python3.6-pip-19.2.3/bin:/nix/store/2xwxj5qrrc71asdk
1wyq19nz9k845pzs-patchelf-0.9/bin:/nix/store/291ldi6fqsbmkbvbs8is4mcg3jb64ld4-gcc-wrapper-8.3.0/bin:/nix/store/62x7m20m7lm8y8s17cbgha0sf3cmma19-gcc-8.3.0/bin:
/nix/store/hblpx8x5w88igmwa4ydnsnb65s363lji-glibc-2.27-bin/bin:/nix/store/9v78r3afqy9xn9zwdj9wfys6sk3vc01d-coreutils-8.31/bin:/nix/store/gwwycf3w6cbj0gd2mpgbl
rdjc24f3cys-binutils-wrapper-2.31.1/bin:/nix/store/ajrrkivdfvp8dp4vdg5hp1h5hblmanc9-binutils-2.31.1/bin:/nix/store/hblpx8x5w88igmwa4ydnsnb65s363lji-glibc-2.27
-bin/bin:/nix/store/9v78r3afqy9xn9zwdj9wfys6sk3vc01d-coreutils-8.31/bin:/nix/store/9v78r3afqy9xn9zwdj9wfys6sk3vc01d-coreutils-8.31/bin:/nix/store/0zdsw4qdrwi4
1mfdwqpxknsvk9fz3gkb-findutils-4.7.0/bin:/nix/store/dys98skw6ifw5qsqrhjxjjiydyfbg3nq-diffutils-3.7/bin:/nix/store/g2h4491kab7l06v9rf1lnyjvzdwy5ak0-gnused-4.7/
bin:/nix/store/71y5ddyz8vmsw9wgi3gzifcls53r60i9-gnugrep-3.3/bin:/nix/store/84yafwjc6sga23vwsbahhymikjhfbnw4-gawk-5.0.1/bin:/nix/store/aawf0q16ql39w2gwv52qyjfz
gbg5f22r-gnutar-1.32/bin:/nix/store/afyqk8219zfv5and3pqahzvn6bpmx3dq-gzip-1.10/bin:/nix/store/iws7dm1jij4lv09mbpwf9i8lc1d4b798-bzip2-1.0.6.0.1-bin/bin:/nix/st
ore/j8fq1ksp37w88rx80blzazldi17f3x7s-gnumake-4.2.1/bin:/nix/store/rm1hz1lybxangc8sdl7xvzs5dcvigvf7-bash-4.4-p23/bin:/nix/store/lmi2nqb1cfzr3ps2zkq97q88zzkhp4m
j-patch-2.7.6/bin:/nix/store/y04xj2mbc66zs53fackn1wwlrv31bv3y-xz-5.2.4-bin/bin:/home/corentin/bin:/run/wrappers/bin:/home/corentin/.nix-profile/bin:/etc/profi
les/per-user/corentin/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin
There’s two docker packages, the normal one, pkgs.docker which most people think of, then there’s the python package docker, which in nix can be accessed as pythonXPackages.docker. The problem is that, you’re bringing in the python package, and not the normal docker package. Your nix file, should probably be:
with import <nixpkgs> {};
with pkgs.python36Packages;
buildPythonPackage rec {
name = "docker-py";
src = ./. ;
propagatedBuildInputs = [ ipython requests six docker_pycreds ];
# tests touch network
doCheck = false;
}
and since docker-py is already in nixpkgs, you could also do something to the effect of:
with import <nixpkgs> {};
pkgs.python36Packages.docker-py.overrideAttrs(oldAttrs: {
src = ./.;
});
I thought just having docker in propagateBuildInputs would bring in the “real” docker, while python36Packages.docker would bring the python package, no?
Also from the output of nix-shell it seems the “real” docker is being pulled in, as expected:
[corentin@nixos-qemu-vm:~/docker-py]$ nix-shell
these derivations will be built:
/nix/store/1n87219zh6iyvpxy3jqp1kcdyxs4gfda-python3.6-prompt_toolkit-2.0.9.drv
/nix/store/4wrx45slm9i89k0cxd81qrhhmz9mkpmn-python3.6-ipython_genutils-0.2.0.drv
/nix/store/63gn39af7pp1iqkr7pickgjxlrmbxbnw-python3.6-backcall-0.1.0.drv
/nix/store/8qllpdirh0rr9w4gcycyqc1rzky4g99h-python3.6-pickleshare-0.7.5.drv
/nix/store/97ffwnh6gqrhqqiribyg673syqf7hs2j-python3.6-parso-0.3.4.drv
/nix/store/am34bn29bwrajp6rrjyyism1dga7im7x-python3.6-Pygments-2.4.2.drv
/nix/store/mw1s2gk3ds8r46ry9s153rxph8dd5fqf-python3.6-jedi-0.13.3.drv
/nix/store/qk48i9iw572ai6gxjvb4ix651mfbkm23-python3.6-decorator-4.4.0.drv
/nix/store/nb3h65n4g86h0q21j8par6fnmhik1dgj-python3.6-traitlets-4.3.2.drv
/nix/store/r8p3lf0lzbxakz583cdj5cx31gzvgyf0-python3.6-ipython-7.6.1.drv
these paths will be fetched (91.40 MiB download, 384.74 MiB unpacked):
/nix/store/015l240xnqkpy69vkn23vgxdcic5fj6z-docker-init-19.03.2
[...]
/nix/store/6jxc2xm06r0hwm7kw0jg37hjjhiiyydw-docker-proxy-7b2b1feb1de4817d522cc372af149ff48d25028e-bin
/nix/store/f8sc98bp5ylg1i33ryl04cvbihh0w308-docker-runc-19.03.2-bin
[...]
/nix/store/fqj82zrh22mdpdb920sgma1inzshga4h-docker-containerd-19.03.2-bin
[...]
/nix/store/mr50kaan2vs4gc40ymwncb2vci25aq7z-docker-19.03.2
[...]
Also, the nix file you propose is just to install the docker-py package no? I actually want a bit more than this: I want to be able to run the tests, which require docker, make and ipython.
the problem is with, and since your second with is the python package set, i think it’s given priority. if you want it unambiguous, then you would need to something to the effect of:
with import <nixpkgs> {};
pkgs.python36Packages.buildPythonPackage rec {
name = "docker-py";
src = ./. ;
propagatedBuildInputs = with pkgs.python36Packages; [ ipython requests six docker_pycreds ];
checkInputs = [ pkgs.docker pkgs.make ];
}
if you just want a shell, and don’t mind using virutalenv, then I would do nix-shell:
with import <nixpkgs> {};
let
python = python36;
in
pkgs.mkShell {
name = "pip-env";
buildInputs = with pkgs; [
python36Packages.ipython
python36Packages.virtualenv
git
make
docker
];
src = null;
shellHook = ''
# Allow the use of wheels.
SOURCE_DATE_EPOCH=$(date +%s)
VENV=dev36env
if test ! -d $VENV; then
virtualenv $VENV
fi
source ./$VENV/bin/activate
export PYTHONPATH=`pwd`/$VENV/${python.sitePackages}/:$PYTHONPATH
'';
}
the problem with trying to run all of the tests inside of the derivations is that it’s a sandbox environment. And it looks like it tries to execute some docker commands which will try to reach out to the public web.
This shell.nix file works perfectly for me @jonringer, thanks a lot If I understand correctly I must use mkShell in shell.nix files while buildPythonPackage is more for building the project, and should probably go to default.nix. Is that right?
buildPythonPackage is meant to build a python package within nixpkgs. If you just want to reference packages in a dev env, then mkshell will satisfy your needs