Created
December 17, 2018 00:32
-
-
Save sveitser/669e87aa33db9cad577030af7d933b3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# Usage | |
# | |
# python2nix my_pypi_package > my_package.nix | |
# | |
# TODO | |
# - accept 'format' as arg | |
# - prepopulate dependencies? | |
set -euo pipefail | |
tmpfile=$(mktemp) | |
pname="$(echo $1 | tr '-' '_')" | |
version=$( | |
curl -sG -H 'Host: pypi.org' -H 'Accept: application/json' \ | |
https://pypi.org/pypi/$1/json | \ | |
jq ".releases | keys | last") | |
>&2 echo "Found version $version" | |
cat > $tmpfile <<EOF | |
with import <nixpkgs> {}; | |
with python3Packages; | |
buildPythonPackage rec { | |
pname = "$pname"; | |
version = $version; | |
format = "wheel"; | |
src = fetchPypi { | |
inherit format pname version; | |
python = "py3"; | |
sha256 = "XXX"; | |
}; | |
} | |
EOF | |
SHA=$(nix-prefetch-url --unpack -A src $tmpfile) | |
rm $tmpfile | |
cat <<EOF | |
{ buildPythonPackage, fetchPypi | |
, python36Packages | |
}: | |
buildPythonPackage rec { | |
pname = "$pname"; | |
version = $version; | |
format = "wheel"; | |
src = fetchPypi { | |
inherit format pname version; | |
python = "py3"; | |
sha256 = "$SHA"; | |
}; | |
# doCheck = false; | |
propagatedBuildInputs = with python36Packages; [ | |
]; | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment