guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#48277] [PATCH 0/1] New wrap-in-search-paths function


From: Edouard Klein
Subject: [bug#48277] [PATCH 0/1] New wrap-in-search-paths function
Date: Fri, 7 May 2021 17:42:08 +0200

This patch adds the wrap-in-search-paths function.

This function takes an executable and a list of packages as arguments, and wrap 
the executable in the search-paths needed by the list of packages.

Two use-cases have pushed me to create this function, but I suspect it may be 
useful in other cases.

First, when running on a foreign distro, guix packages (especially python 
packages) can break the foreign distribution by putting Guix's python 
interpreter before the host's in the PATH. Scripts that rely on a 
#!/usr/bin/env python shebang then breaks. This for example breaks gdm on the 
latest Ubuntu when you install any package for which python is a propagated 
input.

This new function solves this problem by allowing one to write a G-exp that 
wraps the needed execs in the search paths for their packages, without putting 
them in the default profile, therefore avoiding masking the host's command.

A second use case is when defining operating-system-services, the system 
profile is not available to the environment where the command is launched, so 
if this command has any dynamically loaded part (as most executable today do), 
they won't be found despite being installed and present in the system profile.

This new function solves the problem by allowing one to wrap the service 
executable with an activation-service, to that the sheperd-service can launch 
it wihtout having to source the system profile.

See this thread on help-guix to see an example of the problem:
https://lists.gnu.org/archive/html/help-guix/2021-04/msg00100.html

Here is an example that can be built with guix build -f and demonstrate the use 
of the function. The (quite useless) resulting script will output the current 
version of flask, despite the flask binary not being in the current profile's 
PATH:


(use-modules (gnu packages python-web)
             (gnu packages bash)
             (guix gexp)
             (guix modules)
             (guix search-paths)
             (gnu packages guile)
             (gnu packages gnupg))


(with-extensions
 (list guile-zlib guile-gcrypt)
 (with-imported-modules
     (source-module-closure
      '((guix build utils)
        (guix search-paths)
        ))
   #~(begin
       (use-modules (guix build utils)
                    (guix search-paths))
       (mkdir-p (string-append #$output "/bin/"))
       (with-output-to-file (string-append #$output "/bin/flask-version")
         (lambda _
           (display (string-append "#!" #$bash "/bin/bash\n"))
           (display "flask --version\n")))
       (chmod  (string-append #$output "/bin/flask-version") #o755)
       (set-path-environment-variable "PATH" '("bin") (list #$bash))
       #$(wrap-in-search-paths #~(string-append #$output "/bin/flask-version") 
(list python-flask)))))


Edouard Klein (1):
  guix: search-paths: Add wrap-in-search-paths

 guix/search-paths.scm | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

-- 
2.31.1






reply via email to

[Prev in Thread] Current Thread [Next in Thread]