Tool for patching nixpkgs package source code easily
Reason this release was yanked:
broken build
Project description
nix-playground
The nix-playground is a command line tool that makes applying patches to the nixpkgs packages much easier.
Example
# checkout libnvidia-container package source code locally
# (in `nixpkgs` by default, a full pkg path with flake name can be provided like `nixpkgs#cowsay`)
np checkout libnvidia-container
# modify the code
vim checkout/src/cli/main.c
# build the package with changes you made in the checkout folder and try it out
np build
# output the patch for applying on the production environments
np patch > bugfix.patch
# clean up the generated files
np clean
Why
Too often, we are afraid of digging into the upstream code, modifying and patching it because it's a very tedious process. Just getting the project to build could take hours. Thanks to nixpkgs, building open-source software is much easier with a single source tree capable of building from the Linux kernel all the way to a simple utils command-line tool. With nix-playground, now you can easily check out source code from a package, modify it, test it out, and then create patches effortlessly.
Usage
This tool assumes you have nixpkgs with flake and Python >= 3.11 installed on your environment. To install nix-playground, simply run:
pip install nix-playground
Then, you can use the command line tool np (stands for nix-playground).
For example, say you need to apply a patch to libnvidia-container, with the np command, you can run:
np checkout nixpkgs#libnvidia-container
It will check the source code of libnvidia-container in the checkout folder of the current directory.
Next, you can modify the code in the checkout folder. The tool will track changes you made automatically.
Once you're done with the changes and would like to try it out, simply do the following:
np build
It will build the libnvidia-container package with patches from the changes you just made in the checkout folder.
The result will end up in the result folder, just like the nix-build command.
You can test the build. When you're happy with the result and decide to port the patch file to your production environments, you can run the command:
np patch > bugfix.patch
To print the patch file contents. With the patch file, you can then apply it on the target package like this:
with import <nixpkgs> {};
libnvidia-container.overrideAttrs (oldAttrs: {
patches = (lib.attrsets.attrByPath ["patches"] [] oldAttrs) ++ [./bugfix.patch];
})
How it works
Checkout
- Create
.nix-playgroundfolder in the current directory - Call
nix-instantiateto generate the derivation for the target package with a link at.nix-playground/der - Get the
env.srcnix store path from the generated derivation - Run
nix-store --realiseto realise the package and its source derivation with links in the.nix-playgroundfolder. - Deep copy the source (from env.src) folder to the current directory's
checkoutfolder - Init a git repo in the
checkoutfolder and commit all the changes - Apply patches from the package as commits in the
checkoutGit repo if there's any
Build
- Get the cached diff with git for the
checkoutfolder and output the patch file to.nix-playground/checkout.patch - Run
nix-build --exprwith patch file applied to the target package
Roadmap
- Add automatic tests
- Publish it to nixpkgs
- Implement
np shell(likenix-shellbut with the patches applied) - Support patching nested dependency package
- Rewrite it with Rust? 🤔
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 nix_playground-0.1.4.tar.gz.
File metadata
- Download URL: nix_playground-0.1.4.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7da322efe6d8f57eb48ccd35a814377ba7f8f862094fca3ca7caa824d33f13bf
|
|
| MD5 |
5fba50779f28f6b7994377c8b4545fd6
|
|
| BLAKE2b-256 |
9f1e80682c65bc625865138ac101c781f203e26948cce774ed5b654a413eab56
|
File details
Details for the file nix_playground-0.1.4-py3-none-any.whl.
File metadata
- Download URL: nix_playground-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16bf4af410c4a08172104b4eb68ac0824fa2b1c41f0fa641ccabf36f60a564cd
|
|
| MD5 |
870c8a5e84c3df44f8628028886aae37
|
|
| BLAKE2b-256 |
065449a784fa168b6ceacda45e26e3828d5f049885865db3cddf45f406148cfb
|