Skip to content

Instantly share code, notes, and snippets.

@sevanspowell
Last active July 2, 2020 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevanspowell/fd70a66c531ef5ba02cf4e5257dadfc8 to your computer and use it in GitHub Desktop.
Save sevanspowell/fd70a66c531ef5ba02cf4e5257dadfc8 to your computer and use it in GitHub Desktop.
Cloudsmith-cli pypi2nix
let
pkgs = import <nixpkgs> {};
python = import ./requirements.nix { inherit pkgs; };
in
python.mkDerivation rec {
pname = "cloudsmith-cli";
version = "0.22.2";
format = "wheel";
src = pkgs.python.pkgs.fetchPypi {
pname = "cloudsmith_cli";
inherit version format;
sha256 = "1fykhr5kmyb9iw1iww4h3iydf0ldrcf6swqs0kqgk8l26wsx52sc";
};
buildInputs = [];
propagatedBuildInputs = builtins.attrValues python.packages;
# makeWrapperArgs = ["--set PYTHONPATH $PYTHONPATH" "--set LD_LIBRARY_PATH ${pkgs.xmlsec}/lib" ];
}

README

There were two main issue:

  • cloudsmith-api and cloudsmith-cli only provide wheels, no ".tar.gz"s. I'm not sure how to make pypi2nix look for wheels instead. It might already look for wheels, but there's the second problem:
  • cloudsmith-api's file is "cloudsmith_api" and cloudsmith-cli is "cloudsmith_cli" (i.e. that file name and project name don't match)

This is simply fixed by providing an overrides file to pypi2nix that fetches "cloudsmith-api" for it:

pypi2nix -r requirements.txt -O bootstrap_overrides.nix

Process

  • Comment out "cloudsmith-api" in requirements.txt -> successfully generated.
  • Create a "cloudsmith-cli" derivation using the requirements.nix generated, but provide "cloudsmith-cli" via "requirements_override.nix".
  • Fix issues with the override till it works (ensure can fetch source, provide propagatedBuildInputs)
  • Rename "requirements_override" to "bootstrap_override" and feed this back to pypi2nix.
{ pkgs, python }:
self: super: {
cloudsmith-api = python.mkDerivation rec {
pname = "cloudsmith_api";
version = "0.51.38";
format = "wheel";
src = pkgs.python.pkgs.fetchPypi {
inherit pname version format;
sha256 = "17qvkf6ir5vlfn4kazwys95hjnvgy8mlhyav6mj9il9w5zbqdc53";
};
buildInputs = [];
propagatedBuildInputs = with pkgs; [ self.certifi self.urllib3 self.python-dateutil ];
};
}
pypi2nix -r requirements.txt -O bootstrap_overrides.nix
nix-build cloudsmith-cli.nix
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --pre --output-file production.py3.txt common.in
#
--extra-index-url https://dl.cloudsmith.io/public/cloudsmith/api/python/index/
certifi==2019.3.9 # via cloudsmith-api, requests
chardet==3.0.4 # via requests
click-configfile==0.2.3
click-didyoumean==0.0.3
click-spinner==0.1.7
click==7.0
cloudsmith-api==0.51.38
colorama==0.3.9
configparser==3.7.4 # via click-configfile
future==0.17.1
idna==2.8 # via requests
python-dateutil==2.8.0 # via cloudsmith-api
requests==2.21.0
requests_toolbelt==0.8.0
semver==2.8.1
simplejson==3.16.0
six==1.12.0
urllib3==1.24.1 # via cloudsmith-api, requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment