Hi Thomas,

Thomas Danckaert via <help-guix@gnu.org> writes:

> What is the recommended way to set up environment variables for a shepherd 
> service?  Is there a profile associated to the environment of a shepherd 
> service where I could/should install required packages and have the correct 
> environment variables set up automatically?  Specifically, I have a service 
> which uses gobject-introspection (from Python / python-pygobject), and had 
> some difficulty to get it to run recently.

No, there is no profile associated. You would have to do that on your
own, build a profile, and source the /etc/profile in your own shepherd
startup script. System shepherd services run in a minimal environment,
and you add new env vars with #:environment-variables variable of
...forkexec... function.

>
> context (a bit long unfortunately):
>
> I have a shepherd-service which runs a Python script.  The Python script 
> listens on dbus to check if my external backup hard disk is mounted, and 
> starts rsnapshot.
>
> This worked reliably for many years, until a recent guix pull / system 
> reconfigure (moving from guix commit 461d773adead955e2daead70cee4415f7f0f00be 
> -- january 2025 -- to  d8aa9af09f901d1745470caa45ffe2178a9afce1 -- april 2025 
> --so a rather large range of commits unfortunately).  Suddenly, the Python 
> import statement
>
>  import gi.repository.GLib
>
> would fail with exception 'ImportError: cannot import name GLib, 
> introspection typelib not found'.  This seemed to be due to a missing 
> GI_TYPELIB_PATH enviroment variable, which I was able to fix manually by 
> setting it in a wrap-executable phase
>
> (wrap-program (string-append out "/bin/listen_dbus.py")
>                  `("PATH" ":" prefix
>                    (,(string-append rsnapshot "/bin")))
>                  `("GI_TYPELIB_PATH" ":" prefix
>                    (,(string-append glib "/lib/girepository-1.0"))))
>
> I'm wondering if this is the proper way to do this kind of thing?  When 
> installing gobject-instrospection etc in a profile, I know these environment 
> variables are set automatically.

Wrapping is currently the best way to give env vars to programs
when the the program itself requires it for running, yes.

Search paths are set from within a profile, but search paths are
utilized mainly to tell programs where to look for packages they don't
require to actually run. Like python isn't wrapped with pythonpath to
python packages, because it doesn't need them to run. But you can
install python and python packages to a profile, and then your python
has those packages. Wrapping is used when the program/script itself
requires it, always. That is your case, so wrapping is the right course.

>
> I'm also wondering which change caused it to stop working without setting 
> GI_TYPELIB_PATH after January... but that might be difficult to track down (I 
> see an update of python-pygobject happened in that timeframe).

I have no idea as well. Probably something changed after python-team
branch merge.

>
> Thanks for reading this far!
>
> Thomas

Regards,
Rutherther

Reply via email to