Skip to main content

Tools for removing the tedious nature of creating nixpkgs derivations

Project description

python nixpkgs tools

Build Status

These are scripts written to remove the tedious nature of creating nix package derivations for nixpkgs. The goal of these scripts is not to create a perfect package derivation but complete as much as possible and guide the user on necessary changes.


usage: python-package-init [-h] [--version VERSION] [--filename FILENAME] [--stdout] [--nixpkgs-root NIXPKGS_ROOT] [-f] package

positional arguments:
  package               pypi package name

optional arguments:
  -h, --help            show this help message and exit
  --version VERSION     pypi package version (stable if not specified)
  --filename FILENAME   filename for nix derivation
  --stdout              Print the nix derivation to stdout
  --nixpkgs-root NIXPKGS_ROOT
                        Root directory of nixpkgs
  -f, --force           Force creation of file, overwriting when it already exists

python-package-init now has the ability to create a <package-name> = callPackages ../...<package-name> { }; in pkgs/top-level/python-modules.nix and write the default.nix to pkgs/development/python-modules/<package-name>/default.nix with a nearly complete derivation.

Example lets add nixpkgs-pytools to nixpkgs. It is already in nixpkgs so you would need to provide the -f (force) option to force it to be written to nixpkgs.

nix-shell -p nixpkgs-pytools
python-package-init nixpkgs-pytools --nixpkgs-root=<path to nixpkgs>

Creates a default.nix derivation to go into nixpkgs/pkgs/development/python-modules/<pypi-name>/default.nix. This script is overly verbose so that you don't have to remember the name of attributes. Delete the ones that you don't need.


usage: python-rewrite-imports [-h] --path PATH [--replace REPLACE REPLACE]

optional arguments:
  -h, --help            show this help message and exit
  --path PATH           path to refactor imports
                        module import to replace

example rewriting airflow imports

nix-shell -p nixpkgs-pytools

cd /tmp
tar -xf master.tar.gz

python-rewrite-imports --path /tmp/airflow-master \
                       --replace flask_appbuilder flask_appbuilder_1_13_6237336a2b92fa6ba5f7f14dda56c08af6c0a76a \
                       --replace pendulum pendulum_1_4_4_55011d302b80c60360e2cc9f3a5ace7336c727c7

grep -R pendulum /tmp/airflow-master

You'll notice that all imports have been rewritten. Rewrites are done via rope a robust refactoring library used by many text editors.

Hacking on these tools

nix-shell will load the correct environment for your usage:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nixpkgs-pytools-1.2.0.tar.gz (11.7 kB view hashes)

Uploaded Source

Built Distribution

nixpkgs_pytools-1.2.0-py3-none-any.whl (13.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page