Run Nix packages from Python without Nix installed
Project description
nixwrap
Wrap Nix binaries into Python packages for installation via uv tool install.
Overview
nixwrap provides a way to distribute Nix-built binaries as Python packages. When a user installs a nixwrap package (e.g., ripgrep), the PEP 517 build backend:
- Fetches the narinfo and nar from the Nix binary cache
- Verifies the hash
- Extracts the binary
- Builds a wheel containing the binary as package data
Usage
# Install a tool from the nixwrap index
uv tool install --index-url https://elohmeier.github.io/nixwrap/ ripgrep
# Use the tool
rg --version
Repository Structure
nixwrap/
pyproject.toml # nixwrap-core (shared build backend)
src/nixwrap_core/
__init__.py
backend.py # PEP 517 build backend
runtime.py # Runtime binary executor
tools/
manifests/ # Tool manifest files
ripgrep.json
fd.json
build_index.py # Generates sdists + PEP 503 index
.github/workflows/
publish-pages.yml # CI for publishing to GitHub Pages
Adding a New Tool
- Create a manifest file in
tools/manifests/<tool>.json:
{
"name": "ripgrep",
"version": "15.1.0",
"dist": "ripgrep",
"command": "rg",
"description": "A line-oriented search tool",
"store_path": "/nix/store/...-ripgrep-15.1.0",
"bin_relpath": "bin/rg",
"cache_url": "https://cache.nixos.org",
"nar_hash": "sha256:...",
"ld_linux": "lib/ld-linux-x86-64.so.2",
"closure": [
{"store_path": "/nix/store/...-glibc-2.40-66", "nar_hash": "sha256:..."},
{"store_path": "/nix/store/...-pcre2-10.46", "nar_hash": "sha256:..."}
]
}
- Push to main - CI will regenerate the index and publish.
Development
# Install dependencies
uv sync
# Build the index locally
uv run python tools/build_index.py --manifests tools/manifests --out gh-pages
# Test a local install
uv tool install --index-url file://$(pwd)/gh-pages/ ripgrep
How It Works
Build Time (CI)
The build_index.py script:
- Reads each manifest from
tools/manifests/*.json - Creates ephemeral wrapper projects in a temp directory
- Builds sdists using
python -m build --sdist - Generates PEP 503 simple index HTML pages
- Publishes to GitHub Pages
Install Time (User)
When a user runs uv tool install ripgrep:
- uv downloads the sdist from the PEP 503 index
- The PEP 517 build backend (
nixwrap_core.backend) is invoked - The backend fetches the nar files from the Nix cache (main package + closure)
- The binary, dynamic linker, and libraries are extracted and embedded in the wheel
- The wheel is installed with the command available on PATH
- At runtime, the binary is invoked via the bundled dynamic linker
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nixwrap-0.9.1.tar.gz.
File metadata
- Download URL: nixwrap-0.9.1.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16b51eb9dfaf50762928a913631df0e6e4d14bea8eaa19e96342f4b00ba6e7ac
|
|
| MD5 |
fd2b57bf0c8114872816bb8cf0c2e828
|
|
| BLAKE2b-256 |
6ba2d9765eb00538516f8a81b7914ec649cfa1e1d0f013fd3e453ade0dc6f7b1
|
Provenance
The following attestation bundles were made for nixwrap-0.9.1.tar.gz:
Publisher:
publish-pypi.yml on elohmeier/nixwrap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nixwrap-0.9.1.tar.gz -
Subject digest:
16b51eb9dfaf50762928a913631df0e6e4d14bea8eaa19e96342f4b00ba6e7ac - Sigstore transparency entry: 789371590
- Sigstore integration time:
-
Permalink:
elohmeier/nixwrap@7e2a2b9a5d06bf7648e086354dbaa9f92170b1bf -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/elohmeier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7e2a2b9a5d06bf7648e086354dbaa9f92170b1bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file nixwrap-0.9.1-py3-none-any.whl.
File metadata
- Download URL: nixwrap-0.9.1-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b632f76ebc73cc4f9b1fdbfb498463ec80820798534938195d2922156c39db5
|
|
| MD5 |
ece8a208734073a6e341fbb625bebac3
|
|
| BLAKE2b-256 |
6c4000a5c581ef61c34301cc4dc77ef730ab7a1d76f3357eb8eb254643925edc
|
Provenance
The following attestation bundles were made for nixwrap-0.9.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on elohmeier/nixwrap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nixwrap-0.9.1-py3-none-any.whl -
Subject digest:
2b632f76ebc73cc4f9b1fdbfb498463ec80820798534938195d2922156c39db5 - Sigstore transparency entry: 789371603
- Sigstore integration time:
-
Permalink:
elohmeier/nixwrap@7e2a2b9a5d06bf7648e086354dbaa9f92170b1bf -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/elohmeier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7e2a2b9a5d06bf7648e086354dbaa9f92170b1bf -
Trigger Event:
push
-
Statement type: