I have a Python script, workrave-open.py, that I want to package, normally the sort of thing that writePython3Bin
is made for. Trouble is, if I do that, I get the error message, “ValueError: Namespace GLib not available.”
Basically, it needs the environment that would normally come from wrapGAppsNoGuiHook
.
I tried looking at these previous topics:
- https://discourse.nixos.org/t/trying-to-package-a-python-script-but-running-it-doesnt-find-dependency/8335/3
- https://discourse.nixos.org/t/python-glib-introspection-fails/47391
That second topic led me to try this non-working derivation:
{
python3,
python3Packages,
wrapGAppsNoGuiHook,
}:
python3.pkgs.buildPythonApplication {
pname = "workrave-open-py";
version = "0.1.0";
src = ./workrave-open.py;
dontWrapGApps = true;
makeWrapperArgs = [ "\${gappsWrapperArgs[@]}" ];
nativeBuildInputs = [ wrapGAppsNoGuiHook ];
dependencies = [ python3Packages.dasbus ];
}
Again, please don’t try this at home. Well, okay, you can try it, but it’s an example of what not to do.
Anyway, this just gets me the error message, “do not know how to unpack source archive /nix/store/p33cghj9mbgblc7axih7xdglzjpnnqp5-workrave-open.py”.
How do I get this to work?
ETA: Never mind, I forgot about the advice from this: https://discourse.nixos.org/t/struggling-with-nixos-cant-figure-out-how-to-get-some-apps-to-work-without-crude-hacks/66224/15?u=jjramsey
Anyway, the overlay packaging the working script is this:
final: prev:
{
workrave-open-py = prev.writers.writePython3Bin "workrave-open.py" {
libraries = with prev.python3Packages; [ dasbus ];
# If you read the docs I link below, you can see that `makeWrapper`
# is exposed to all script writers like this.
#
# Unfortunately, `wrapGapps` *isn't* exposed, so we need to do
# this "manually". This may or may not become awkward depending
# on how involved your script actually is, at which point you should just
# make a custom derivation - which isn't much more complex tbh, this
# maybe saves 3 lines.
makeWrapperArgs = [
"--set" "GI_TYPELIB_PATH" "${prev.glib.out}/lib/girepository-1.0"
];
flakeIgnore = [ "E265" "E251" ];
} ./workrave-open.py;
}