Hi Ben,
Ben Sturmfels <[email protected]> writes: > Hi Folks, > > I have a small Python script that sends me desktop notifications > to help > remind me to stop staring at the screen and go to bed on time. I'd > like to > turn it into a Guix home service, but I'm struggling and would > love some > advice. first step when using scripts with Guix is to package it properly. When speaking about python scripts that means to make a wrapper script that will set the pythonpath properly. This is already taken care of by the python/pyproject build system's wrap phase. So you can use it, adding this phase after install phase. It will work as long as the script is installed in the bin folder in the output. Using propagated inputs is completely unnecessary when packaging an application, to use them instead of wrapping, you would have to evaluate the search paths and set them, easiest is to use a profile and source its .../etc/profile file. But this is unnecessary when packaging scripts/applications. Those should be wrapped in the first place. > > Source for package, service and example home config is here: > https://git.sr.ht/~sturm/bedtime/tree > > I can run the script like this, which works fine: > > $ guix shell libnotify python python-pygobject dbus -- python3 > -u bedtime.py > > I've added a package "bedtime" in bedtime.scm. That works fine > too: > > $ guix shell -L . bedtime -- python3 -u bedtime.py > > For what it's worth, both these commands fail if I add > --pure. This seems like a > potential issue: That is expected, because your script uses dbus. Dbus needs to know what socket to connect to. The env var DBUS_SESSION_BUS_ADDRESS is for that. If you're using guix home, the env var is pointed to `unix:path=/run/user/$USER/bus` by default. So you can just set it to that in your shepherd-service's make-forkexec-constructor. > > defau guix shell libnotify python python-pygobject dbus -- python3 > -u bedtime.py > Traceback (most recent call last): > ... > File "/home/ben/repos/bedtime/bedtime.py", line 47, in > notify_of_bedtime > Notify.Notification.new("Starting bedtime reminder").show() > gi.repository.GLib.GError: g-dbus-error-quark: > GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name > org.freedesktop.Notifications was not provided by any .service > files (2) > > I've tried to create an initial Guix home service > "home-bedtime-service-type" in > bedtime.scm. I can install this with `guix home` but it seems to > fail, unable to > find the dependency python-pygobject (gi): > > $ guix home reconfigure -L . home-example.scm > $ herd enable bedtime > $ herd start bedtime > $ tail -f ~/.local/state/shepherd/bedtime.log > 2025-06-08 16:15:56 Traceback (most recent call last): > 2025-06-08 16:15:56 File > "/gnu/store/39sw79zg00y94l8rpxxh1l3rn65gjydm-bedtime-0/bin/bedtime.py", > line 10, in <module> > 2025-06-08 16:15:56 import gi > 2025-06-08 16:15:56 ModuleNotFoundError: No module named 'gi' Since your script is not wrapped, there is no GUIX_PYTHONPATH set. So python doesn't know any modules, this is expected. After wrapping is done, it should work to execute the py file directly. Note that for wrapping to work properly, you will need to switch to a shebang (just put #!/usr/bin/env python3 and it will get replaced), so that your script is executable directly (and add the executable flag if it isn't there currently) > > Regards, > Ben Rutherther
