Subject: bug#22629: [PATCH v2 2/3] Add (guix describe) and use it to initialize '%package-search-path'.

From: Ricardo Wurmus <[email-masked]>
Date: Fri, 31 Aug 2018 14:21:30 +0200

Hi Ludo,

> * guix/describe.scm: New file.
> * Makefile.am (MODULES): Add it.
> * gnu/packages.scm (%default-package-module-path): New variable.
> (%package-module-path): Honor 'package-path-entries'.
> * build-aux/update-NEWS.scm (main): Use %DEFAULT-PACKAGE-MODULE-PATH
> instead of (last (%package-module-path)).
> ---
[…]
> +(define %default-package-module-path
> +  ;; Default search path for package modules.
> +  `((,%distro-root-directory . "gnu/packages")))
> +
>  (define %package-module-path
>    ;; Search path for package modules.  Each item must be either a directory
>    ;; name or a pair whose car is a directory and whose cdr is a sub-directory
>    ;; to narrow the search.
>    (let* ((not-colon   (char-set-complement (char-set #\:)))
>           (environment (string-tokenize (or (getenv "GUIX_PACKAGE_PATH") "")
> -                                       not-colon)))
> -    ;; Automatically add items from $GUIX_PACKAGE_PATH to Guile's search path.
> -    (for-each (lambda (directory)
> -                (set! %load-path (cons directory %load-path))
> -                (set! %load-compiled-path
> -                      (cons directory %load-compiled-path)))
> -              environment)
> +                                       not-colon))
> +         (channels    (package-path-entries)))
> +    ;; Automatically add channels and items from $GUIX_PACKAGE_PATH to Guile's
> +    ;; search path.  For historical reasons, $GUIX_PACKAGE_PATH goes to the
> +    ;; front; channels go to the back so that they don't override Guix' own
> +    ;; modules.
> +    (set! %load-path
> +      (append environment %load-path channels))
> +    (set! %load-compiled-path
> +      (append environment %load-compiled-path channels))
>
>      (make-parameter
> -     (append environment `((,%distro-root-directory . "gnu/packages"))))))
> +     (append environment
> +             %default-package-module-path
> +             channels))))

I’m not sure I understand the reason to add channels to the end of the
search path.  Could it not be desirable in some use-cases to override
certain Guix modules?  Should the order be made explicit in the channel
to avoid having to accomodate “historical reasons” in the future? :)

Putting them at the end probably ensures that Guix itself won’t break
and can thus be rolled back.

> diff --git a/guix/describe.scm b/guix/describe.scm
> new file mode 100644
> index 000000000..3122a762f
> --- /dev/null
> +++ b/guix/describe.scm
[…]
> +(define current-profile
> +  (mlambda ()
> +    "Return the profile (created by 'guix pull') the calling process lives in,
> +or #f if this is not applicable."
> +    (match (command-line)
> +      ((program . _)
> +       (and (string-suffix? "/bin/guix" program)
> +            ;; Note: We want to do _lexical dot-dot resolution_.  Using ".."
> +            ;; for real would instead take us into the /gnu/store directory
> +            ;; that ~/.config/guix/current/bin points to, whereas we want to
> +            ;; obtain ~/.config/guix/current.
> +            (let ((candidate (dirname (dirname program))))
> +              (and (file-exists? (string-append candidate "/manifest"))
> +                   candidate)))))))

I don’t know… there’s something about this file system traversal that
doesn’t sit right with me.  I’m not sure about (command-line) — when
…/bin/guix is executed by a wrapper, will the wrapper be the “program”
that we match against or the target?  (This is a concern for wrappers
that set up site-wide default channels or a remote daemon, for example.)

--
Ricardo