I have been using NixOS for about 6-8 months now and it has been a pretty good experience compared with other distros, mainly due to the stability (which comes from the reproducibility of the packaging system). For a university project I now need to install a Python library that is not in nixpkgs (Control). I have been struggling to find any clear resources on how to do this, as they all assume familiarity with Python packaging (with pypi or pipenv or poetry or what have you), or they assume an in-depth understanding of Nix. I have neither.
My question is: what is the best way to install the Control Python library and how can I make it easier to install other non-Nix libraries in the future? Should I just create a virtual machine or container running some other distribution of Linux?
You have a lot of great options in the Python - NixOS Wiki page, but I personally find devenv the easiest and cleanest one so far. It also has first-class support for native libraries, so you don’t have to worry about whether a package will work or not.
After you install devenv, just run the following command inside your project to get started:
$ devenv init
Then, you can write a requirement.txt if you don’t have one, yet:
# requirememnt.txt
control==0.10.0
We could have directly added the packages in venv.requirements, but it might be cleaner to just read them, instead:
$ devenv shell
• Building shell ...
✔ Building shell in 1.1s.
• Entering shell
No errors!
Of course devenv is capable of a lot of things like running processes and services for you. If you’re interested to know more, I highly recommend you read the documentation.
You’re right, we’re passing the program directly from the command line instead of running it from a file. So if python failed to load the module, we would have an error instead and the echo command wouldn’t run.
Therefore we have a quick way to know whether the library has been installed correctly or not.