Subject: [bug#35282] [PATCHv2] gnu: docker: Patch paths of xz and docker-proxy.

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 15 Apr 2019 16:19:12 -0400

Hello again,

Actually, the proposed change was not sufficient, as it would transform
reexec.Command -> exec.Command. The attached series fixes it (patch
0003, with the other rebased).

From 1405716eff1c15bf2a44704f4a32e6e823f73bf2 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Thu, 11 Apr 2019 21:55:48 -0400
Subject: [PATCH 1/7] gnu: docker: Fix indentation.

* gnu/packages/docker.scm (docker): Fix indentation using Emacs.
---
 gnu/packages/docker.scm | 184 ++++++++++++++++++++--------------------
 1 file changed, 92 insertions(+), 92 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 1067555296..7445856347 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -299,17 +299,17 @@ built-in registry server of Docker.")
     (version %docker-version)
     (source
      (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/docker/engine.git")
-            (commit (string-append "v" version))))
-      (file-name (git-file-name name version))
-      (sha256
-       (base32 "06yr5xwr181lalh8z1lk07nxlp7hn38aq8cyqjk617dfy4lz0ixx"))
-      (patches
-       (search-patches "docker-engine-test-noinstall.patch"
-                       "docker-fix-tests.patch"
-                       "docker-use-fewer-modprobes.patch"))))
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/docker/engine.git")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "06yr5xwr181lalh8z1lk07nxlp7hn38aq8cyqjk617dfy4lz0ixx"))
+       (patches
+        (search-patches "docker-engine-test-noinstall.patch"
+                        "docker-fix-tests.patch"
+                        "docker-use-fewer-modprobes.patch"))))
     (build-system gnu-build-system)
     (arguments
      `(#:modules
@@ -326,77 +326,77 @@ built-in registry server of Docker.")
          (add-after 'unpack 'patch-paths
            (lambda* (#:key inputs #:allow-other-keys)
              (substitute* "builder/builder-next/executor_unix.go"
-              (("CommandCandidates:.*runc.*")
-               (string-append "CommandCandidates: []string{\""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"},\n")))
+               (("CommandCandidates:.*runc.*")
+                (string-append "CommandCandidates: []string{\""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"},\n")))
              (substitute* "vendor/github.com/containerd/go-runc/runc.go"
-              (("DefaultCommand = .*")
-               (string-append "DefaultCommand = \""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"\n")))
+               (("DefaultCommand = .*")
+                (string-append "DefaultCommand = \""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"\n")))
              (substitute* "vendor/github.com/containerd/containerd/runtime/v1/linux/runtime.go"
-              (("defaultRuntime[ \t]*=.*")
-               (string-append "defaultRuntime = \""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"\n"))
-              (("defaultShim[ \t]*=.*")
-               (string-append "defaultShim = \""
-                              (assoc-ref inputs "containerd")
-                              "/bin/containerd-shim\"\n")))
+               (("defaultRuntime[ \t]*=.*")
+                (string-append "defaultRuntime = \""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"\n"))
+               (("defaultShim[ \t]*=.*")
+                (string-append "defaultShim = \""
+                               (assoc-ref inputs "containerd")
+                               "/bin/containerd-shim\"\n")))
              (substitute* "daemon/daemon_unix.go"
-              (("DefaultShimBinary = .*")
-               (string-append "DefaultShimBinary = \""
-                              (assoc-ref inputs "containerd")
-                              "/bin/containerd-shim\"\n"))
-              (("DefaultRuntimeBinary = .*")
-               (string-append "DefaultRuntimeBinary = \""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"\n"))
-              (("DefaultRuntimeName = .*")
-               (string-append "DefaultRuntimeName = \""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"\n")))
+               (("DefaultShimBinary = .*")
+                (string-append "DefaultShimBinary = \""
+                               (assoc-ref inputs "containerd")
+                               "/bin/containerd-shim\"\n"))
+               (("DefaultRuntimeBinary = .*")
+                (string-append "DefaultRuntimeBinary = \""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"\n"))
+               (("DefaultRuntimeName = .*")
+                (string-append "DefaultRuntimeName = \""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"\n")))
              (substitute* "daemon/config/config.go"
-              (("StockRuntimeName = .*")
-               (string-append "StockRuntimeName = \""
-                              (assoc-ref inputs "runc")
-                              "/sbin/runc\"\n")))
+               (("StockRuntimeName = .*")
+                (string-append "StockRuntimeName = \""
+                               (assoc-ref inputs "runc")
+                               "/sbin/runc\"\n")))
              (substitute* "vendor/github.com/moby/buildkit/executor/runcexecutor/executor.go"
-              (("var defaultCommandCandidates = .*")
-               (string-append "var defaultCommandCandidates = []string{\""
-                              (assoc-ref inputs "runc") "/sbin/runc\"}")))
+               (("var defaultCommandCandidates = .*")
+                (string-append "var defaultCommandCandidates = []string{\""
+                               (assoc-ref inputs "runc") "/sbin/runc\"}")))
              (let ((source-files (filter (lambda (name)
-                                    (not (string-contains name "test")))
-                                  (find-files "." "\\.go$"))))
+                                           (not (string-contains name "test")))
+                                         (find-files "." "\\.go$"))))
                (let-syntax ((substitute-LookPath
                              (lambda (x)
                                (syntax-case x ()
                                  ((substitute-LookPath source-text package
                                                        relative-path)
                                   #`(substitute* source-files
-                                     ((#,(string-append "exec\\.LookPath\\(\""
-                                                        (syntax->datum
-                                                         #'source-text)
-                                                        "\")"))
-                                      (string-append "\""
-                                                     (assoc-ref inputs package)
-                                                     relative-path
-                                                     "\", error(nil)")))))))
+                                      ((#,(string-append "exec\\.LookPath\\(\""
+                                                         (syntax->datum
+                                                          #'source-text)
+                                                         "\")"))
+                                       (string-append "\""
+                                                      (assoc-ref inputs package)
+                                                      relative-path
+                                                      "\", error(nil)")))))))
                             (substitute-Command
                              (lambda (x)
                                (syntax-case x ()
                                  ((substitute-LookPath source-text package
                                                        relative-path)
                                   #`(substitute* source-files
-                                     ((#,(string-append "exec\\.Command\\(\""
-                                                        (syntax->datum
-                                                         #'source-text)
-                                                        "\"")) ; )
-                                      (string-append "exec.Command(\""
-                                                     (assoc-ref inputs package)
-                                                     relative-path
-                                                     "\"")))))))) ; )
+                                      ((#,(string-append "exec\\.Command\\(\""
+                                                         (syntax->datum
+                                                          #'source-text)
+                                                         "\"")) ; )
+                                       (string-append "exec.Command(\""
+                                                      (assoc-ref inputs package)
+                                                      relative-path
+                                                      "\"")))))))) ; )
                  (substitute-LookPath "ps" "procps" "/bin/ps")
                  (substitute-LookPath "mkfs.xfs" "xfsprogs" "/bin/mkfs.xfs")
                  (substitute-LookPath "lvmdiskscan" "lvm2" "/sbin/lvmdiskscan")
@@ -418,13 +418,13 @@ built-in registry server of Docker.")
                  (substitute-Command "tune2fs" "e2fsprogs" "/sbin/tune2fs")
                  (substitute-Command "blkid" "util-linux" "/sbin/blkid")
                  (substitute-Command "resize2fs" "e2fsprogs" "/sbin/resize2fs")
-; docker-mountfrom ??
-; docker
-; docker-untar ??
-; docker-applyLayer ??
-; /usr/bin/uname
-; grep
-; apparmor_parser
+                 ;; docker-mountfrom ??
+                 ;; docker
+                 ;; docker-untar ??
+                 ;; docker-applyLayer ??
+                 ;; /usr/bin/uname
+                 ;; grep
+                 ;; apparmor_parser
                  (substitute-Command "ps" "procps" "/bin/ps")
                  (substitute-Command "losetup" "util-linux" "/sbin/losetup")
                  (substitute-Command "uname" "coreutils" "/bin/uname")
@@ -434,24 +434,24 @@ built-in registry server of Docker.")
                ;; invokes other programs we don't know about and thus don't
                ;; substitute.
                (substitute* source-files
-                ;; Search for Java in PATH.
-                (("\\<exec\\.Command\\(\"java\"") ; )
-                 "xxec.Command(\"java\"") ; )
-                ;; Search for AUFS in PATH (mainline Linux doesn't support it).
-                (("\\<exec\\.Command\\(\"auplink\"") ; )
-                 "xxec.Command(\"auplink\"") ; )
-                ;; Fail on other unsubstituted commands.
-                (("\\<exec\\.Command\\(\"([a-zA-Z0-9][a-zA-Z0-9_-]*)\""
-                  _ executable) ; )
-                 (string-append "exec.Guix_doesnt_want_Command(\""
-                                executable "\"")) ;)
-                (("\\<xxec\\.Command")
-                 "exec.Command")
-                ;; Search for ZFS in PATH.
-                (("\\<LookPath\\(\"zfs\"\\)") "LooxPath(\"zfs\")")
-                ;; Fail on other unsubstituted LookPaths.
-                (("\\<LookPath\\(\"") "Guix_doesnt_want_LookPath\\(\"") ; ))
-                (("\\<LooxPath") "LookPath")))
+                 ;; Search for Java in PATH.
+                 (("\\<exec\\.Command\\(\"java\"") ; )
+                  "xxec.Command(\"java\"")         ; )
+                 ;; Search for AUFS in PATH (mainline Linux doesn't support it).
+                 (("\\<exec\\.Command\\(\"auplink\"") ; )
+                  "xxec.Command(\"auplink\"")         ; )
+                 ;; Fail on other unsubstituted commands.
+                 (("\\<exec\\.Command\\(\"([a-zA-Z0-9][a-zA-Z0-9_-]*)\""
+                   _ executable)        ; )
+                  (string-append "exec.Guix_doesnt_want_Command(\""
+                                 executable "\"")) ;)
+                 (("\\<xxec\\.Command")
+                  "exec.Command")
+                 ;; Search for ZFS in PATH.
+                 (("\\<LookPath\\(\"zfs\"\\)") "LooxPath(\"zfs\")")
+                 ;; Fail on other unsubstituted LookPaths.
+                 (("\\<LookPath\\(\"") "Guix_doesnt_want_LookPath\\(\"") ; ))
+                 (("\\<LooxPath") "LookPath")))
              #t))
          (add-after 'patch-paths 'delete-failing-tests
            (lambda _
@@ -498,7 +498,7 @@ built-in registry server of Docker.")
              ;; But go needs to have the uncanonicalized directory name, so
              ;; store that.
              (setenv "PWD" (string-append (getcwd)
-                            "/.gopath/src/github.com/docker/docker"))
+                                          "/.gopath/src/github.com/docker/docker"))
              (with-directory-excursion ".gopath/src/github.com/docker/docker"
                (invoke "hack/test/unit"))
              (setenv "PWD" #f)
@@ -512,7 +512,7 @@ built-in registry server of Docker.")
                #t))))))
     (inputs
      `(("btrfs-progs" ,btrfs-progs)
-       ("containerd" ,containerd) ; for containerd-shim
+       ("containerd" ,containerd)       ; for containerd-shim
        ("coreutils" ,coreutils)
        ("dbus" ,dbus)
        ("e2fsprogs" ,e2fsprogs)
@@ -528,7 +528,7 @@ built-in registry server of Docker.")
        ("lvm2" ,lvm2)
        ("xfsprogs" ,xfsprogs)))
     (native-inputs
-     `(("eudev" ,eudev) ; TODO: Should be propagated by lvm2 (.pc -> .pc)
+     `(("eudev" ,eudev)      ; TODO: Should be propagated by lvm2 (.pc -> .pc)
        ("go" ,go)
        ("pkg-config" ,pkg-config)))
     (synopsis "Docker container component library, and daemon")
-- 
2.20.1

From 64b8226b954c18aa9fd246c26b8c5958fa5d2e86 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Thu, 11 Apr 2019 22:08:52 -0400
Subject: [PATCH 2/7] gnu: docker: Cleanup extraneous comments.

* gnu/packages/docker.scm (docker): Remove "parenthesis-balancing" comments.
---
 gnu/packages/docker.scm | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 7445856347..10aa3aa5b4 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -392,11 +392,11 @@ built-in registry server of Docker.")
                                       ((#,(string-append "exec\\.Command\\(\""
                                                          (syntax->datum
                                                           #'source-text)
-                                                         "\"")) ; )
+                                                         "\""))
                                        (string-append "exec.Command(\""
                                                       (assoc-ref inputs package)
                                                       relative-path
-                                                      "\"")))))))) ; )
+                                                      "\""))))))))
                  (substitute-LookPath "ps" "procps" "/bin/ps")
                  (substitute-LookPath "mkfs.xfs" "xfsprogs" "/bin/mkfs.xfs")
                  (substitute-LookPath "lvmdiskscan" "lvm2" "/sbin/lvmdiskscan")
@@ -435,22 +435,22 @@ built-in registry server of Docker.")
                ;; substitute.
                (substitute* source-files
                  ;; Search for Java in PATH.
-                 (("\\<exec\\.Command\\(\"java\"") ; )
-                  "xxec.Command(\"java\"")         ; )
+                 (("\\<exec\\.Command\\(\"java\"")
+                  "xxec.Command(\"java\"")
                  ;; Search for AUFS in PATH (mainline Linux doesn't support it).
-                 (("\\<exec\\.Command\\(\"auplink\"") ; )
-                  "xxec.Command(\"auplink\"")         ; )
+                 (("\\<exec\\.Command\\(\"auplink\"")
+                  "xxec.Command(\"auplink\"")
                  ;; Fail on other unsubstituted commands.
                  (("\\<exec\\.Command\\(\"([a-zA-Z0-9][a-zA-Z0-9_-]*)\""
-                   _ executable)        ; )
+                   _ executable)
                   (string-append "exec.Guix_doesnt_want_Command(\""
-                                 executable "\"")) ;)
+                                 executable "\""))
                  (("\\<xxec\\.Command")
                   "exec.Command")
                  ;; Search for ZFS in PATH.
                  (("\\<LookPath\\(\"zfs\"\\)") "LooxPath(\"zfs\")")
                  ;; Fail on other unsubstituted LookPaths.
-                 (("\\<LookPath\\(\"") "Guix_doesnt_want_LookPath\\(\"") ; ))
+                 (("\\<LookPath\\(\"") "Guix_doesnt_want_LookPath\\(\"")
                  (("\\<LooxPath") "LookPath")))
              #t))
          (add-after 'patch-paths 'delete-failing-tests
-- 
2.20.1

From 9d7cc43b251061b15dbd70f0fe45696ec7b55f2e Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Thu, 11 Apr 2019 22:12:00 -0400
Subject: [PATCH 3/7] gnu: docker: Harmonize LookPath regexes.

* gnu/packages/docker.scm (docker)[phases]: In the patch-paths phase, update
the regexes used by SUBSTITUTE-LOOKPATH and SUBSTITUTE-COMMAND to match at the
start of the word, like it's done later.
---
 gnu/packages/docker.scm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 10aa3aa5b4..ce9d4d4643 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -375,7 +375,7 @@ built-in registry server of Docker.")
                                  ((substitute-LookPath source-text package
                                                        relative-path)
                                   #`(substitute* source-files
-                                      ((#,(string-append "exec\\.LookPath\\(\""
+                                      ((#,(string-append "\\<exec\\.LookPath\\(\""
                                                          (syntax->datum
                                                           #'source-text)
                                                          "\")"))
@@ -389,11 +389,12 @@ built-in registry server of Docker.")
                                  ((substitute-LookPath source-text package
                                                        relative-path)
                                   #`(substitute* source-files
-                                      ((#,(string-append "exec\\.Command\\(\""
+                                      ((#,(string-append "\\<(re)?exec\\.Command\\(\""
                                                          (syntax->datum
                                                           #'source-text)
-                                                         "\""))
-                                       (string-append "exec.Command(\""
+                                                         "\"") _ re?)
+                                       (string-append (if re? re? "")
+                                                      "exec.Command(\""
                                                       (assoc-ref inputs package)
                                                       relative-path
                                                       "\""))))))))
-- 
2.20.1

From 8776742130efab07e2f00287d039ec2fbf5e21bf Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Thu, 11 Apr 2019 22:57:33 -0400
Subject: [PATCH 4/7] gnu: docker: Make macros use a relative path as argument.

* gnu/packages/docker.scm (docker)[phases]: Move implementation detail inside
the SUBSTITUTE-LOOKPATH and SUBSTITUTE-COMMAND macros definition, so that the
relative path argument can be given as a relative path.
---
 gnu/packages/docker.scm | 56 ++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index ce9d4d4643..f6e0e813ba 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -381,7 +381,7 @@ built-in registry server of Docker.")
                                                          "\")"))
                                        (string-append "\""
                                                       (assoc-ref inputs package)
-                                                      relative-path
+                                                      "/" relative-path
                                                       "\", error(nil)")))))))
                             (substitute-Command
                              (lambda (x)
@@ -396,29 +396,29 @@ built-in registry server of Docker.")
                                        (string-append (if re? re? "")
                                                       "exec.Command(\""
                                                       (assoc-ref inputs package)
-                                                      relative-path
+                                                      "/" relative-path
                                                       "\""))))))))
-                 (substitute-LookPath "ps" "procps" "/bin/ps")
-                 (substitute-LookPath "mkfs.xfs" "xfsprogs" "/bin/mkfs.xfs")
-                 (substitute-LookPath "lvmdiskscan" "lvm2" "/sbin/lvmdiskscan")
-                 (substitute-LookPath "pvdisplay" "lvm2" "/sbin/pvdisplay")
-                 (substitute-LookPath "blkid" "util-linux" "/sbin/blkid")
-                 (substitute-LookPath "unpigz" "pigz" "/bin/unpigz")
-                 (substitute-LookPath "iptables" "iptables" "/sbin/iptables")
-                 (substitute-LookPath "iptables-legacy" "iptables" "/sbin/iptables")
-                 (substitute-LookPath "ip" "iproute2" "/sbin/ip")
-                 (substitute-Command "modprobe" "kmod" "/bin/modprobe")
-                 (substitute-Command "pvcreate" "lvm2" "/sbin/pvcreate")
-                 (substitute-Command "vgcreate" "lvm2" "/sbin/vgcreate")
-                 (substitute-Command "lvcreate" "lvm2" "/sbin/lvcreate")
-                 (substitute-Command "lvconvert" "lvm2" "/sbin/lvconvert")
-                 (substitute-Command "lvchange" "lvm2" "/sbin/lvchange")
-                 (substitute-Command "mkfs.xfs" "xfsprogs" "/sbin/mkfs.xfs")
-                 (substitute-Command "xfs_growfs" "xfsprogs" "/sbin/xfs_growfs")
-                 (substitute-Command "mkfs.ext4" "e2fsprogs" "/sbin/mkfs.ext4")
-                 (substitute-Command "tune2fs" "e2fsprogs" "/sbin/tune2fs")
-                 (substitute-Command "blkid" "util-linux" "/sbin/blkid")
-                 (substitute-Command "resize2fs" "e2fsprogs" "/sbin/resize2fs")
+                 (substitute-LookPath "ps" "procps" "bin/ps")
+                 (substitute-LookPath "mkfs.xfs" "xfsprogs" "bin/mkfs.xfs")
+                 (substitute-LookPath "lvmdiskscan" "lvm2" "sbin/lvmdiskscan")
+                 (substitute-LookPath "pvdisplay" "lvm2" "sbin/pvdisplay")
+                 (substitute-LookPath "blkid" "util-linux" "sbin/blkid")
+                 (substitute-LookPath "unpigz" "pigz" "bin/unpigz")
+                 (substitute-LookPath "iptables" "iptables" "sbin/iptables")
+                 (substitute-LookPath "iptables-legacy" "iptables" "sbin/iptables")
+                 (substitute-LookPath "ip" "iproute2" "sbin/ip")
+                 (substitute-Command "modprobe" "kmod" "bin/modprobe")
+                 (substitute-Command "pvcreate" "lvm2" "sbin/pvcreate")
+                 (substitute-Command "vgcreate" "lvm2" "sbin/vgcreate")
+                 (substitute-Command "lvcreate" "lvm2" "sbin/lvcreate")
+                 (substitute-Command "lvconvert" "lvm2" "sbin/lvconvert")
+                 (substitute-Command "lvchange" "lvm2" "sbin/lvchange")
+                 (substitute-Command "mkfs.xfs" "xfsprogs" "sbin/mkfs.xfs")
+                 (substitute-Command "xfs_growfs" "xfsprogs" "sbin/xfs_growfs")
+                 (substitute-Command "mkfs.ext4" "e2fsprogs" "sbin/mkfs.ext4")
+                 (substitute-Command "tune2fs" "e2fsprogs" "sbin/tune2fs")
+                 (substitute-Command "blkid" "util-linux" "sbin/blkid")
+                 (substitute-Command "resize2fs" "e2fsprogs" "sbin/resize2fs")
                  ;; docker-mountfrom ??
                  ;; docker
                  ;; docker-untar ??
@@ -426,11 +426,11 @@ built-in registry server of Docker.")
                  ;; /usr/bin/uname
                  ;; grep
                  ;; apparmor_parser
-                 (substitute-Command "ps" "procps" "/bin/ps")
-                 (substitute-Command "losetup" "util-linux" "/sbin/losetup")
-                 (substitute-Command "uname" "coreutils" "/bin/uname")
-                 (substitute-Command "dbus-launch" "dbus" "/bin/dbus-launch")
-                 (substitute-Command "git" "git" "/bin/git"))
+                 (substitute-Command "ps" "procps" "bin/ps")
+                 (substitute-Command "losetup" "util-linux" "sbin/losetup")
+                 (substitute-Command "uname" "coreutils" "bin/uname")
+                 (substitute-Command "dbus-launch" "dbus" "bin/dbus-launch")
+                 (substitute-Command "git" "git" "bin/git"))
                ;; Make compilation fail when, in future versions, Docker
                ;; invokes other programs we don't know about and thus don't
                ;; substitute.
-- 
2.20.1

From 6599410beb1b71bfdd71658554cecc08d7471e3a Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sat, 13 Apr 2019 22:00:45 -0400
Subject: [PATCH 5/7] gnu: docker: Optimize substitution macros.

This change halves the time needed to patch the paths.

* gnu/packages/docker.scm (docker)[phases]{patch-paths}: Allow passing
multiple SOURCE-TEXT, PACKAGE and RELATIVE-PATH tuples so that the rewrite
rules can be generated and processed by a single use of the SUBSTITUTE*
macro.  Rename SUBSTITUTE-LOOKPATH to SUBSTITUTE-LOOKPATH* and
substitute-Command to SUBSTITUTE-COMMAND* to denote the change.  Adapt the
uses of SUBSTITUTE-LOOKPATH* and SUBSTITUTE-COMMAND*.
---
 gnu/packages/docker.scm | 122 ++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 62 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index f6e0e813ba..3cd989cfcb 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -369,68 +369,66 @@ built-in registry server of Docker.")
              (let ((source-files (filter (lambda (name)
                                            (not (string-contains name "test")))
                                          (find-files "." "\\.go$"))))
-               (let-syntax ((substitute-LookPath
-                             (lambda (x)
-                               (syntax-case x ()
-                                 ((substitute-LookPath source-text package
-                                                       relative-path)
-                                  #`(substitute* source-files
-                                      ((#,(string-append "\\<exec\\.LookPath\\(\""
-                                                         (syntax->datum
-                                                          #'source-text)
-                                                         "\")"))
-                                       (string-append "\""
-                                                      (assoc-ref inputs package)
-                                                      "/" relative-path
-                                                      "\", error(nil)")))))))
-                            (substitute-Command
-                             (lambda (x)
-                               (syntax-case x ()
-                                 ((substitute-LookPath source-text package
-                                                       relative-path)
-                                  #`(substitute* source-files
-                                      ((#,(string-append "\\<(re)?exec\\.Command\\(\""
-                                                         (syntax->datum
-                                                          #'source-text)
-                                                         "\"") _ re?)
-                                       (string-append (if re? re? "")
-                                                      "exec.Command(\""
-                                                      (assoc-ref inputs package)
-                                                      "/" relative-path
-                                                      "\""))))))))
-                 (substitute-LookPath "ps" "procps" "bin/ps")
-                 (substitute-LookPath "mkfs.xfs" "xfsprogs" "bin/mkfs.xfs")
-                 (substitute-LookPath "lvmdiskscan" "lvm2" "sbin/lvmdiskscan")
-                 (substitute-LookPath "pvdisplay" "lvm2" "sbin/pvdisplay")
-                 (substitute-LookPath "blkid" "util-linux" "sbin/blkid")
-                 (substitute-LookPath "unpigz" "pigz" "bin/unpigz")
-                 (substitute-LookPath "iptables" "iptables" "sbin/iptables")
-                 (substitute-LookPath "iptables-legacy" "iptables" "sbin/iptables")
-                 (substitute-LookPath "ip" "iproute2" "sbin/ip")
-                 (substitute-Command "modprobe" "kmod" "bin/modprobe")
-                 (substitute-Command "pvcreate" "lvm2" "sbin/pvcreate")
-                 (substitute-Command "vgcreate" "lvm2" "sbin/vgcreate")
-                 (substitute-Command "lvcreate" "lvm2" "sbin/lvcreate")
-                 (substitute-Command "lvconvert" "lvm2" "sbin/lvconvert")
-                 (substitute-Command "lvchange" "lvm2" "sbin/lvchange")
-                 (substitute-Command "mkfs.xfs" "xfsprogs" "sbin/mkfs.xfs")
-                 (substitute-Command "xfs_growfs" "xfsprogs" "sbin/xfs_growfs")
-                 (substitute-Command "mkfs.ext4" "e2fsprogs" "sbin/mkfs.ext4")
-                 (substitute-Command "tune2fs" "e2fsprogs" "sbin/tune2fs")
-                 (substitute-Command "blkid" "util-linux" "sbin/blkid")
-                 (substitute-Command "resize2fs" "e2fsprogs" "sbin/resize2fs")
-                 ;; docker-mountfrom ??
-                 ;; docker
-                 ;; docker-untar ??
-                 ;; docker-applyLayer ??
-                 ;; /usr/bin/uname
-                 ;; grep
-                 ;; apparmor_parser
-                 (substitute-Command "ps" "procps" "bin/ps")
-                 (substitute-Command "losetup" "util-linux" "sbin/losetup")
-                 (substitute-Command "uname" "coreutils" "bin/uname")
-                 (substitute-Command "dbus-launch" "dbus" "bin/dbus-launch")
-                 (substitute-Command "git" "git" "bin/git"))
+               (let-syntax ((substitute-LookPath*
+                             (syntax-rules ()
+                               ((_ (source-text package relative-path) ...)
+                                (substitute* source-files
+                                  (((string-append "\\<exec\\.LookPath\\(\""
+                                                   source-text
+                                                   "\")"))
+                                   (string-append "\""
+                                                  (assoc-ref inputs package)
+                                                  "/" relative-path
+                                                  "\", error(nil)")) ...))))
+                            (substitute-Command*
+                             (syntax-rules ()
+                               ((_ (source-text package relative-path) ...)
+                                (substitute* source-files
+                                  (((string-append "\\<(re)?exec\\.Command\\(\""
+                                                   source-text
+                                                   "\"") _ re?)
+                                   (string-append (if re? re? "")
+                                                  "exec.Command(\""
+                                                  (assoc-ref inputs package)
+                                                  "/" relative-path
+                                                  "\"")) ...)))))
+                 (substitute-LookPath*
+                  ("ps" "procps" "bin/ps")
+                  ("mkfs.xfs" "xfsprogs" "bin/mkfs.xfs")
+                  ("lvmdiskscan" "lvm2" "sbin/lvmdiskscan")
+                  ("pvdisplay" "lvm2" "sbin/pvdisplay")
+                  ("blkid" "util-linux" "sbin/blkid")
+                  ("unpigz" "pigz" "bin/unpigz")
+                  ("iptables" "iptables" "sbin/iptables")
+                  ("iptables-legacy" "iptables" "sbin/iptables")
+                  ("ip" "iproute2" "sbin/ip"))
+
+                 (substitute-Command*
+                  ("modprobe" "kmod" "bin/modprobe")
+                  ("pvcreate" "lvm2" "sbin/pvcreate")
+                  ("vgcreate" "lvm2" "sbin/vgcreate")
+                  ("lvcreate" "lvm2" "sbin/lvcreate")
+                  ("lvconvert" "lvm2" "sbin/lvconvert")
+                  ("lvchange" "lvm2" "sbin/lvchange")
+                  ("mkfs.xfs" "xfsprogs" "sbin/mkfs.xfs")
+                  ("xfs_growfs" "xfsprogs" "sbin/xfs_growfs")
+                  ("mkfs.ext4" "e2fsprogs" "sbin/mkfs.ext4")
+                  ("tune2fs" "e2fsprogs" "sbin/tune2fs")
+                  ("blkid" "util-linux" "sbin/blkid")
+                  ("resize2fs" "e2fsprogs" "sbin/resize2fs")
+                  ("ps" "procps" "bin/ps")
+                  ("losetup" "util-linux" "sbin/losetup")
+                  ("uname" "coreutils" "bin/uname")
+                  ("dbus-launch" "dbus" "bin/dbus-launch")
+                  ("git" "git" "bin/git")))
+               ;; docker-mountfrom ??
+               ;; docker
+               ;; docker-untar ??
+               ;; docker-applyLayer ??
+               ;; /usr/bin/uname
+               ;; grep
+               ;; apparmor_parser
+
                ;; Make compilation fail when, in future versions, Docker
                ;; invokes other programs we don't know about and thus don't
                ;; substitute.
-- 
2.20.1

From 28ab7d7810a1dbcf67254939ab49354651cd8a7c Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sat, 13 Apr 2019 22:48:09 -0400
Subject: [PATCH 6/7] gnu: docker: Patch the reference to the docker proxy.

* gnu/packages/docker.scm (docker)[inputs]: Add docker-libnetwork-cmd-proxy.
* gnu/packages/docker.scm (docker)[phases]{patch-paths}: Patch proxy.go to
refer to the docker-proxy binary by its absolute path.
---
 gnu/packages/docker.scm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 3cd989cfcb..16bc812dd7 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -366,6 +366,11 @@ built-in registry server of Docker.")
                (("var defaultCommandCandidates = .*")
                 (string-append "var defaultCommandCandidates = []string{\""
                                (assoc-ref inputs "runc") "/sbin/runc\"}")))
+             (substitute* "vendor/github.com/docker/libnetwork/portmapper/proxy.go"
+               (("var userlandProxyCommandName = .*")
+                (string-append "var userlandProxyCommandName = \""
+                               (assoc-ref inputs "docker-proxy")
+                               "/bin/proxy\"\n")))
              (let ((source-files (filter (lambda (name)
                                            (not (string-contains name "test")))
                                          (find-files "." "\\.go$"))))
@@ -514,6 +519,7 @@ built-in registry server of Docker.")
        ("containerd" ,containerd)       ; for containerd-shim
        ("coreutils" ,coreutils)
        ("dbus" ,dbus)
+       ("docker-proxy" ,docker-libnetwork-cmd-proxy)
        ("e2fsprogs" ,e2fsprogs)
        ("git" ,git)
        ("iproute2" ,iproute)
-- 
2.20.1

From 9809ec36652d4949af65eb75755e9dd6d8da5c40 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sat, 13 Apr 2019 22:58:55 -0400
Subject: [PATCH 7/7] gnu: docker: Refer to xz by its absolute path.

* gnu/packages/docker.scm (docker)[inputs]: Add xz.
[phases]{patch-paths}: Patch the reference to xz.
---
 gnu/packages/docker.scm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 16bc812dd7..43071775e4 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -371,6 +371,9 @@ built-in registry server of Docker.")
                 (string-append "var userlandProxyCommandName = \""
                                (assoc-ref inputs "docker-proxy")
                                "/bin/proxy\"\n")))
+             (substitute* "pkg/archive/archive.go"
+               (("string\\{\"xz")
+                (string-append "string{\"" (assoc-ref inputs "xz") "/bin/xz")))
              (let ((source-files (filter (lambda (name)
                                            (not (string-contains name "test")))
                                          (find-files "." "\\.go$"))))
@@ -531,7 +534,8 @@ built-in registry server of Docker.")
        ("runc" ,runc)
        ("util-linux" ,util-linux)
        ("lvm2" ,lvm2)
-       ("xfsprogs" ,xfsprogs)))
+       ("xfsprogs" ,xfsprogs)
+       ("xz" ,xz)))
     (native-inputs
      `(("eudev" ,eudev)      ; TODO: Should be propagated by lvm2 (.pc -> .pc)
        ("go" ,go)
-- 
2.20.1

Thanks!

Maxim