Skip to content

Instantly share code, notes, and snippets.

@sveitser
Created January 27, 2021 06:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sveitser/3de73f7dcf649dd4047460367ac3daee to your computer and use it in GitHub Desktop.
Save sveitser/3de73f7dcf649dd4047460367ac3daee to your computer and use it in GitHub Desktop.
#!/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