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

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

* guix/scripts/pack.scm: add store directory to the docker
layer.
* guix/docker.scm: change order of arguments to tar so parent
directories are added before their contents.

Fixes <https://issues.guix.gnu.org/78210>

Change-Id: I2b103c59981e828c965564ccc5d2415b00a7e52e
---
guix/docker.scm       | 4 ++--
guix/scripts/pack.scm | 8 +++++---
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/guix/docker.scm b/guix/docker.scm
index 60ce13cbde..9911bb84bb 100644
--- a/guix/docker.scm
+++ b/guix/docker.scm
@@ -365,10 +365,10 @@ (define* (build-docker-image image paths prefix
                 (apply invoke "tar" "-cf" "../layer.tar"
                        `(,@transformation-options
                          ,@(tar-base-options)
-                         ,@(if max-layers '() paths)
                          ,@(scandir "."
                                     (lambda (file)
-                                      (not (member file '("." ".."))))))))
+                                      (not (member file '("." "..")))))
+                         ,@(if max-layers '() paths))))
               (delete-file-recursively "extra")))

         ;; It is possible for "/" to show up in the archive, especially 
when
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index 7ab2c0d447..9c14b7bd81 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -551,7 +551,8 @@ (define* (docker-image name profile
                                     (guix build store-copy)
                                     (guix build utils) ;for 
%xz-parallel-args
                                     (guix profiles)
-                                    (guix search-paths))
+                                    (guix search-paths)
+                                    (guix store))
                                   #:select? not-config?))
         #~(begin
             (use-modules (guix docker) (guix build store-copy)
@@ -580,9 +581,10 @@ (define* (docker-image name profile
                      (,source -> ,target))))))

             (define directives
-              ;; Create a /tmp directory, as some programs expect it, and
-              ;; create SYMLINKS.
+              ;; Create /tmp and %store-prefix directories, as some
+              ;; programs expect them, and create SYMLINKS.
               `((directory "/tmp" ,(getuid) ,(getgid) #o1777)
+                (directory #$(%store-prefix) ,(getuid) ,(getgid) #o755)
                 ,@(append-map symlink->directives '#$symlinks)))

             (define (form-entry-point prefix entry-point 
entry-point-argument)

base-commit: 096dedd0bb13523002c814b001429c2f65b6f10d
-- 
2.49.0