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

From: Ray Miller <[email-masked]>
Date: Fri, 2 May 2025 11:43:16 +0100

This patch adds the /gnu and /gnu/store directories to the Docker layer
created by `guix pack -f docker ...` which enables the Docker image to be
used to create an AWS Lambda function. Without the patch, creating the AWS
Lambda function fails with this error:

"MissingParentDirectory: Parent directory does not exist for file: 
gnu/store/zic27jikg36d6wjj4cz8hyriyfl3ygiz-info-dir/"

My first attempt to fix this was just to add the /gnu and /gnu/store 
directories
to `directives` but the Docker image failed in AWS Lambda with the same 
error. These
directories need to appear in the tarball for the layer *before* the 
packages,
so the change to the order of the tar arguments is also needed.

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

Change-Id: I2b103c59981e828c965564ccc5d2415b00a7e52e
---
guix/docker.scm       | 4 ++--
guix/scripts/pack.scm | 6 ++++--
2 files changed, 6 insertions(+), 4 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..5cb9cd0b48 100644
--- a/guix/scripts/pack.scm
+++ 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)
                 ,@(append-map symlink->directives '#$symlinks)))

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

base-commit: 4fe4cf9fdd959126d3c53c3df4504d851e7b736a
-- 
2.47.1