Subject: Re: [PATCH] environment: Provide a writable /run/user/$UID.

From: Tomas Volf <[email-masked]>
Date: Tue, 20 May 2025 01:29:47 +0200

Ludovic Courtès <[email-masked]> writes:

> * guix/scripts/environment.scm (launch-environment/container): Add
> /run/user/UID to ‘file-systems’.
> * tests/guix-environment-container.sh: Test it.
>
> Change-Id: I44c70a7554a06f40d073c25929ea7c6ded356d08
> ---
>  guix/scripts/environment.scm        | 5 +++++
>  tests/guix-environment-container.sh | 3 +++
>  2 files changed, 8 insertions(+)
>
> Hello Guix!
>
> This may sound like a recurring joke but hey! when running shepherd
> in ‘guix shell -C’, I figured that a writable /run/user/$UID would
> be welcome too.
>
> Thoughts?

I just wonder how many more we will need :)  Cannot really think of any,
so hopefully this is it?

>
> Ludo’.
>
> diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
> index 96bbc6c9fa..1c2d222c74 100644
> --- a/guix/scripts/environment.scm
> +++ b/guix/scripts/environment.scm
> @@ -875,6 +875,11 @@ (define* (launch-environment/container #:key command bash user user-mappings
>                     reqs)))
>              (file-systems (append %container-file-systems
>                                    (list tmpfs        ; RW /tmp
> +                                        (file-system ; RW /run
> +                                          (inherit tmpfs)
> +                                          (mount-point
> +                                           (string-append "/run/user/"
> +                                                          (number->string uid))))

For normal users this is fine, but for root the whole /run should be
writable, the way it is on normal system.  Thoughts?

>                                          (file-system ; RW ~
>                                            (device "none")
>                                            (mount-point
> diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh
> index e1c3655846..220e6b8ec8 100644
> --- a/tests/guix-environment-container.sh
> +++ b/tests/guix-environment-container.sh
> @@ -203,6 +203,9 @@ guix environment --bootstrap --container --ad-hoc guile-bootstrap \
>  guix environment --bootstrap --container --ad-hoc guile-bootstrap \
>       -- guile -c '(mkdir (string-append (getenv "HOME") "/foo"))'
>
> +# And /run too!
> +guix environment --bootstrap --container --ad-hoc guile-bootstrap \
> +     -- guile -c '(mkdir "/run/user/1000/shepherd")'
>
>  # Check the exit code.
>
>
> base-commit: 11e88de06043d367d02ceceade84733a65f84e27

Did not test, but looks good (and since it has the test, we know it
works).  Just left a comment for consideration.

Reviewed-by: Tomas Volf <[email-masked]>

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.