Created
January 27, 2021 06:57
-
-
Save sveitser/3de73f7dcf649dd4047460367ac3daee 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 '-' '_')" | |
pname="$1" | |
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; | |
src = fetchPypi { | |
inherit pname version; | |
sha256 = "XXX"; | |
}; | |
} | |
EOF | |
SHA=$(nix-prefetch-url --unpack -A src $tmpfile) | |
rm $tmpfile | |
cat <<EOF | |
{ buildPythonPackage | |
, fetchPypi | |
}: | |
buildPythonPackage rec { | |
pname = "$pname"; | |
version = $version; | |
src = fetchPypi { | |
inherit pname version; | |
sha256 = "$SHA"; | |
}; | |
propagatedBuildInputs = [ | |
]; | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment