Subject: [bug#78210] [PATCH] guix: include store parent dirs in docker layer

From: Ray Miller <[email-masked]>
Date: Sat, 24 May 2025 17:53:16 +0100

Hi Ludo,

Thank you for the feedback and suggestions.

On 18/05/2025 21:34, Ludovic Courtès wrote:
> Neat!
>
> Could you include in the commit log a line like:
>
>    Fixes <https://issues.guix.gnu.org/XYZ>.
>
> … so we can keep track of where this was reported and discussed?
>
Done.

>> +++ b/guix/scripts/pack.scm
>> @@ -580,9 +580,11 @@ (define* (docker-image name profile
>>                        (,source -> ,target))))))
>>
>>               (define directives
>> -              ;; Create a /tmp directory, as some programs expect it, and
>> -              ;; create SYMLINKS.
>> +              ;; Create /tmp, /gnu, and /gnu/store directories, as some
>> +              ;; programs expect them, and create SYMLINKS.
>>                 `((directory "/tmp" ,(getuid) ,(getgid) #o1777)
>> +                (directory "/gnu" ,(getuid) ,(getgid) #o755)
>> +                (directory "/gnu/store" ,(getuid) ,(getgid) #o755)
> It’s a bit trickier, because “/gnu/store” is not hardcoded.
Ah, OK. Good catch!
> Instead, you need to recurse over the components of (%store-prefix), so
> something like:
>
>    `((directory "/tmp" …)
>      #$@(map (lambda (component)
>                #~(directory #$component …))
>              (string-tokenize (%store-prefix)
>                               (char-set-complement (char-set #\/)))))

It turns out to be a bit simpler because these directives are processed by
evaluate-populate-directive which calls mkdir-p. (I discovered this after
implementing a recursive solution then thinking "there must be a better
way" and reading some source code...)

> But perhaps this should actually be done in (guix docker) so that ‘guix
> system image -t docker’ also benefits from it?
I tested this by running 'guix systemimage -t docker' and inspecting the
layer it generates. It turns out not to suffer from the same problem: the
store directory is present in the layer.

Updated patch to follow.

Ray.