I often create nix environments/derivations/flakes with other people’s Python packages using mach-nix
. Very frequently mach-nix
won’t build the Python packages due to "Requirements conflict"s. Sometimes overriding the requirements in mach-nix suffices (using the mach-nix requirements
attribute) but if I need to remove a dependency the requirements of the Python package must be changed. I find the following procedure to be most convenient:
- Copy the Python packages requirements.txt the nix project dir
- Create a patch that removes the
requirements.txt
from the Python package (sometimes I also editsetup.py
) - Edit the copy of requirements until a satisfactory build is achieved
More specifically:
Starting from my Nix project repo
git clone some/.../baz.git
cd baz
cp requirement.txt ../requirements-baz.txt
rm requirements.txt
git diff > ../baz.patch
cd ..
rm -rf baz
Now I use a block like this in my derivation
baz = machNix.buildPythonPackage {
src = builtins.fetchGit{
url = "https://.../baz.git";
ref = "master";
rev = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
};
patches = [
./baz.patch # deletes package requirements.txt
];
requirements = builtins.readFile ./requirements-baz.txt ;
};
Here I edit requirements-baz.txt
.
Perhaps someone will find this useful.