Hi,
"Tanguy Le Carrour" <[email protected]> writes:
> Hi Guix,
>
> I have a bunch of web services, written in Python using Flask, and I would
> love to run them as Guix services, but I cannot figure out how to make that
> work!?
> The only example I could put my hands on is `patchwork-service-type`, but it’s
> different for it provides its own script to run the web server,
> `patchwork-admin`.
>
> [..]
>
> The only way I’ve found to make `gunicorn` "see" `gertrude` is by modifying
> the `PYTHONPATH`. This works, but it doesn’t see the package
> `propagated-inputs`.
> I don’t feel like adding all the package dependencies to the `PYTHONPATH`
> is the proper way to solve the problem, right?
>
> Am I missing something obvious?!
The way that works for me is to write a wrapper script, that invoked the
commands required. And that wrapper scripts is wrapped using
wrap-program. I needed to solve this for Guile, not for Python, but I
imagine the problem is basically identical.
In a local package I am doing this in the arguments:
--8<---------------cut here---------------start------------->8---
(arguments
(list
#:imported-modules (append (source-module-closure '((guix search-paths)))
%default-gnu-imported-modules)
#:modules `((guix search-paths)
,@%default-gnu-modules)
#:phases
#~(modify-phases %standard-phases
;; I hope there is a better way.
(add-after 'install 'wrap
(lambda* (#:key inputs #:allow-other-keys)
(let* ((directories (cons #$output (map cdr inputs)))
(guile-bin (search-input-file inputs "bin/guile"))
(load-path
(cdar (evaluate-search-paths
(list (search-path-specification
(variable "GUILE_LOAD_PATH")
(files '("share/guile/site/3.0"))))
directories)))
(load-compiled-path
(cdar (evaluate-search-paths
(list (search-path-specification
(variable "GUILE_LOAD_COMPILED_PATH")
(files '("lib/guile/3.0/site-ccache"
"share/guile/site/3.0"))))
directories)))
(extension-path
(cdar (evaluate-search-paths
(list (search-path-specification
(variable "GUILE_EXTENSIONS_PATH")
(files (list "lib/guile/3.0/extensions"))))
directories)))
(ssl-cert-dir
(cdar (evaluate-search-paths
(list $SSL_CERT_DIR)
'(#$nss-certs)))))
(wrap-program (string-append #$output "/bin/forgejo-feed")
`("LC_CTYPE" = ("C.UTF-8"))
`("GUILE_LOAD_PATH" = (,load-path))
`("GUILE_LOAD_COMPILED_PATH" = (,load-compiled-path))
`("GUILE_EXTENSIONS_PATH" = (,extension-path))
`("PATH" = (,(dirname guile-bin)))
`("SSL_CERT_DIR" = (,ssl-cert-dir)))))))))
--8<---------------cut here---------------end--------------->8---
My application has an actual entry point, "bin/forgejo-feed", but in
your case you could just have a script that execs the gunicorn with the
right arguments (and wrap it using the above).
This allows me to use the resulting output script directly from shepherd
service, with all environment being correctly set up.
It would be great if there was some `wrap-program-in-profile' procedure,
but alas, no such thing exists (currently).
Maybe this will help,
Tomas
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.