Struggling with NixOS: Can't figure out how to get some apps to work without crude hacks

Looks like what’s happening is that the imports are done within the environment set by the derivation.

One thing I notice is that if I run a Python script that depends on pydbus within a shell started by nix-shell -p python3Packages.pydbus, then the script actually works. Which is what @tejing was trying to tell me when he was talking about nix-shell shebangs, but I didn’t quite get it then.

I think I’m finally getting at least a good chunk of the answer to this question:

It looks to me like the “Nix way” for avoiding dependency problems in Python (and probably Perl and R as well) can be described as “Never run a naked interpreter”. Replace instances of #!/usr/bin/env <my_interpreter> with #!/usr/bin/env nix-shell followed by #!nix-shell -i <my_interpreter> -p <python module 1> <python module 2> .... Alternatively, use Python distributions like Anaconda, conda-forge, etc., that provide their own ways of handling environments and dependencies (though I’d personally tend to reserve those for more scientific uses). That’s at least making sense to me.

That doesn’t solve my problems with the Workrave GNOME extension, but that’s at least as much of a packaging issue as anything.

1 Like