Last active
October 5, 2020 09:33
-
-
Save knedlsepp/35403bdad29458dcdaf29b0983c6b294 to your computer and use it in GitHub Desktop.
An example on how to use python39 on nixpkgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To get a development shell use: | |
# nix-shell | |
# To get a development shell for python37 use: | |
# nix-shell --arg getPythonVersion "(p: p.python37Packages)" | |
# To build with pinned nixpkgs use: | |
# nix-build | |
# To develop/build with your custom nixpkgs (from $NIX_PATH) use: | |
# nix-shell --arg nixpkgs "<nixpkgs>" | |
# nix-build --arg nixpkgs "<nixpkgs>" | |
{ | |
nixpkgs ? (builtins.fetchGit { | |
url = "https://github.com/NixOS/nixpkgs.git"; | |
ref = "release-20.09"; | |
rev = "55a8dcdc532ee199513ca1e0824a72a72d6d8aef"; | |
}) | |
, getPythonVersion ? (p: p.python38Packages) | |
, src ? builtins.fetchGit ./. | |
}: | |
let | |
our_custom_python_overlay = (self: super: with self; { | |
python3 = python37; | |
python3Packages = python37Packages; | |
python37 = super.python37.override { packageOverrides = pythonOverrides; }; | |
python37Packages = super.recurseIntoAttrs (python37.pkgs); | |
python38 = super.python38.override { packageOverrides = pythonOverrides; }; | |
python38Packages = super.recurseIntoAttrs (python38.pkgs); | |
python39 = super.python39.override { packageOverrides = pythonOverrides; }; | |
python39Packages = super.recurseIntoAttrs (python39.pkgs); | |
pythonOverrides = python-self: python-super: { | |
rope = python-super.rope.overrideAttrs (o: { | |
doInstallCheck = true; | |
}); | |
astroid = python-super.astroid.overrideAttrs (o: rec { | |
name = "${pname}-${version}"; | |
pname = "astroid"; | |
version = "2.4.3pre"; | |
src = fetchFromGitHub { | |
owner = "PyCQA"; | |
repo = "astroid"; | |
rev = "1d14e985baf8847be60b81b7f6140e8606fd862a"; | |
sha256 = "0br6xczwbi98n177jv269mh0qhqp7wz548vlq7blzd0ccpjxy3wd"; | |
}; | |
}); | |
pylint = python-super.pylint.overrideAttrs (o: rec { | |
name = "${pname}-${version}"; | |
pname = "pylint"; | |
version = "2.6.0"; | |
src = python-super.fetchPypi { | |
inherit pname version; | |
sha256 = "040j0sz76gb9ypyh9hpjr411m3pmf3l501c632n3mg5dkn690jmv"; | |
}; | |
}); | |
pyflakes = python-super.pyflakes.overrideAttrs (o: rec { | |
name = "${pname}-${version}"; | |
pname = "pyflakes"; | |
version = "2.2.1pre"; | |
src = fetchFromGitHub { | |
owner = "PyCQA"; | |
repo = "pyflakes"; | |
rev = "6a5f38b5ab12260fde8a0463acd433bc2d34dbcf"; | |
sha256 = "0qn4l22bcixyi8q7zbyvzc7a64fg5asib1z53ah6yaa9gkdhabi0"; | |
}; | |
}); | |
}; | |
}); | |
pkgs = import nixpkgs { | |
overlays = [ our_custom_python_overlay ]; | |
}; | |
pyPkgs = getPythonVersion pkgs; | |
in with pkgs; pyPkgs.buildPythonPackage rec { | |
name = "python-example"; | |
inherit src; | |
propagatedBuildInputs = with pyPkgs; [ | |
numpy | |
pandas | |
pint | |
]; | |
nativeBuildInputs = with pyPkgs; pkgs.lib.optionals (pkgs.lib.inNixShell) [ | |
ipython | |
python-language-server | |
]; | |
checkInputs = with pyPkgs; [ | |
pytest | |
pytestrunner | |
pytest-flake8 | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment