Python that just works.
I have seen countless threads on the NixOS forums discussing various ways of getting Python on NixOS to "just work". However, as there appear to be so many ways of going about, whether it is poetry2nix, uv2nix, direnv, making an FHS-compliant nix-shell etc, I just want stuff to work. I am mainly doing computer vision with Python, and I really like the idea of Nix and NixOS. I have fixed a few issues by installing nix-ld using opencv-python-headless, but I still recieve a few errors like "libgtk2.0-dev" missing etc. I feel like there has got to be a way of making this process seamless, and not needing to manually write flakes of nix-shells or even a custom setup_venv.py. Also, I am using VS code as my IDE.
Update:
After searching through different forums and posts on Reddit, I found a shell.nix I thought looked promising. The issue however is that with this shell OpenCV compiles from source causing an OOM on my machine and killing the process. I will try a few more things, but if those fail I will probably leave move to another distro. It's simply unacceptable to spend a few days or even a week just to get 1 (!) dependency to "kind of" work. As I'm not sure if this is a "one of a kind issue", here is the shell.nix so others can try it out:
{ pkgs ? import <nixpkgs> {} }:
let
pythonEnv = pkgs.python311.withPackages (ps: with ps; [
# Add other Python packages here
(ps.opencv4.override { enableGtk2 = true; })
]);
in pkgs.mkShell {
nativeBuildInputs = [ pkgs.python311Packages.virtualenv ];
buildInputs = [ pythonEnv ];
shellHook = ''
echo "Welcome to my Python project environment!"
'';
}