Subject: [bug#58812] [PATCH 0/5] Add --symlink option to 'guix shell'.

From: Ludovic Courtès <[email-masked]>
Date: Wed, 09 Nov 2022 21:58:45 +0100

Hi,

That looks like a useful improvement!  Some comments below.

Maxim Cournoyer <[email-masked]> skribis:

> +@item --symlink=@var{spec}
> +@itemx -S @var{spec}
> +For containers, create the symbolic links specified by @var{spec}, as
> +documented in @ref{pack-symlink-option}.

We should refrain from using @ref in sentences (info "(texinfo) @ref").
Instead, I’d write:

  documented for @command{guix pack} (@pxref{pack-symlink-option}).

>  (define-module (gnu build install)
> +  #:use-module ((guix build union) #:select (relative-file-name))
>    #:use-module (guix build syscalls)
>    #:use-module (guix build utils)
>    #:use-module (guix build store-copy)
> @@ -26,6 +27,7 @@ (define-module (gnu build install)
>    #:use-module (ice-9 match)
>    #:export (install-boot-config
>              evaluate-populate-directive
> +            make-symlink->directives
>              populate-root-file-system
>              install-database-and-gc-roots
>              populate-single-profile-directory
> @@ -124,6 +126,22 @@ (define target* (if (string-suffix? "/" target)
>                  directive)
>          (apply throw args)))))
>  
> +(define (make-symlink->directives directory)
> +  "Return a procedure that turn symlinks specs into directives that target
> +DIRECTORY."
> +  (match-lambda
> +    ((source '-> target)
> +     (let ((target (string-append directory "/" target))
> +           (parent (dirname source)))
> +       ;; Never add a 'directory' directive for "/" so as to preserve its
> +       ;; ownership and avoid adding the same entries multiple times.
> +       `(,@(if (string=? parent "/")
> +               '()
> +               `((directory ,parent)))
> +         ;; Note: a relative file name is used for compatibility with
> +         ;; relocatable packs.
> +         (,source -> ,(relative-file-name parent target)))))))

I think it’s a case where I would refrain from factorizing because this
procedure, as shown by the comments and the use of ‘relative-file-name’,
is specifically tailored for the needs to ‘guix pack -f tarball’.

I’d prefer to have a similar but independently maintained variant of
this procedure in (guix scripts environment) to avoid difficulties down
the road.

> +++ b/guix/scripts/environment.scm
> @@ -33,8 +33,10 @@ (define-module (guix scripts environment)
>    #:use-module ((guix gexp) #:select (lower-object))
>    #:use-module (guix scripts)
>    #:use-module (guix scripts build)
> +  #:use-module ((guix scripts pack) #:select (symlink-spec-option-parser))

You can turn this into #:autoload so we don’t pay the price when not
using ‘--symlink’.

> +++ b/tests/guix-shell.sh
> @@ -20,6 +20,8 @@
>  # Test the 'guix shell' alias.
>  #
>  
> +. tests/utils.sh
> +
>  guix shell --version
>  
>  configdir="t-guix-shell-config-$$"
> @@ -32,6 +34,21 @@ export XDG_CONFIG_HOME
>  
>  guix shell --bootstrap --pure guile-bootstrap -- guile --version
>  
> +# '--symlink' can only be used with --container.
> +! guix shell --bootstrap guile-bootstrap -S /dummy=bin/guile
> +
> +if has_container_support; then
> +    # '--symlink' works.
> +    echo "TESTING SYMLINK IN CONTAINER"
> +    guix shell --bootstrap guile-bootstrap --container \
> +         --symlink=/usr/bin/guile=bin/guile -- \
> +         /usr/bin/guile --version

This should go to ‘tests/guix-environment-container.sh’, which has all
the container-related tests.

Thanks,
Ludo’.