summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-05-10 18:16:45 +0200
committerLudovic Courtès <ludo@gnu.org>2019-05-15 16:36:21 +0200
commit6edd5c546c7c1bb5ee45436a0441a9daf1e5509c (patch)
treedf58794499e3ba22c85bff5192fe3fd76d4cedc5 /gnu
parent32747aa987bd921bc8aadc1c1d4b4da6d9bcc306 (diff)
linux-container: Do not add %CONTAINER-FILE-SYSTEMS to Docker image OSes.
Previously, 'guix system docker-image' would end up providing an OS that would try to mount all of %CONTAINER-FILE-SYSTEMS as well as /gnu/store, which is bound to fail in unprivileged Docker. This patch makes it so that 'guix system container' still gets those file systems, but 'guix system docker-image' doesn't. * gnu/system/linux-container.scm (containerized-operating-system): Add #:extra-file-systems parameter and honor it. Do not include %STORE-MAPPING and SHARED-NETWORK-FILE-MAPPINGS. (container-script): Add %STORE-MAPPING and optionally NETWORK-MAPPINGS to MAPPINGS and pass #:extra-file-systems.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/system/linux-container.scm47
1 files changed, 23 insertions, 24 deletions
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index ce786e39b22..0cfd7efd994 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -65,10 +65,13 @@ from OS that are needed on the bare metal and not in a container."
65 files))) 65 files)))
66 base))) 66 base)))
67 67
68(define* (containerized-operating-system os mappings #:key shared-network?) 68(define* (containerized-operating-system os mappings
69 #:key
70 shared-network?
71 (extra-file-systems '()))
69 "Return an operating system based on OS for use in a Linux container 72 "Return an operating system based on OS for use in a Linux container
70environment. MAPPINGS is a list of <file-system-mapping> to realize in the 73environment. MAPPINGS is a list of <file-system-mapping> to realize in the
71containerized OS." 74containerized OS. EXTRA-FILE-SYSTEMS is a list of file systems to add to OS."
72 (define user-file-systems 75 (define user-file-systems
73 (remove (lambda (fs) 76 (remove (lambda (fs)
74 (let ((target (file-system-mount-point fs)) 77 (let ((target (file-system-mount-point fs))
@@ -96,19 +99,6 @@ containerized OS."
96 (list nscd-service-type) 99 (list nscd-service-type)
97 (list)))) 100 (list))))
98 101
99 (define shared-network-file-mappings
100 ;; Files to map if network is to be shared with the host
101 (append %network-file-mappings
102 (let ((nscd-run-directory "/var/run/nscd"))
103 (if (file-exists? nscd-run-directory)
104 (list (file-system-mapping
105 (source nscd-run-directory)
106 (target nscd-run-directory)))
107 (list)))))
108
109 ;; (write shared-network-file-mappings)
110 ;; (newline)
111
112 (operating-system 102 (operating-system
113 (inherit os) 103 (inherit os)
114 (swap-devices '()) ; disable swap 104 (swap-devices '()) ; disable swap
@@ -118,23 +108,32 @@ containerized OS."
118 (memq (service-kind service) 108 (memq (service-kind service)
119 useless-services)) 109 useless-services))
120 (operating-system-user-services os))) 110 (operating-system-user-services os)))
121 (file-systems (append (map mapping->fs 111 (file-systems (append (map mapping->fs mappings)
122 (cons %store-mapping 112 extra-file-systems
123 (append mappings
124 (if shared-network?
125 shared-network-file-mappings
126 (list)))))
127 %container-file-systems
128 user-file-systems)))) 113 user-file-systems))))
129 114
130(define* (container-script os #:key (mappings '()) shared-network?) 115(define* (container-script os #:key (mappings '()) shared-network?)
131 "Return a derivation of a script that runs OS as a Linux container. 116 "Return a derivation of a script that runs OS as a Linux container.
132MAPPINGS is a list of <file-system> objects that specify the files/directories 117MAPPINGS is a list of <file-system> objects that specify the files/directories
133that will be shared with the host system." 118that will be shared with the host system."
119 (define network-mappings
120 ;; Files to map if network is to be shared with the host
121 (append %network-file-mappings
122 (let ((nscd-run-directory "/var/run/nscd"))
123 (if (file-exists? nscd-run-directory)
124 (list (file-system-mapping
125 (source nscd-run-directory)
126 (target nscd-run-directory)))
127 '()))))
128
134 (let* ((os (containerized-operating-system 129 (let* ((os (containerized-operating-system
135 os 130 os
136 mappings 131 (cons %store-mapping
137 #:shared-network? shared-network?)) 132 (if shared-network?
133 (append network-mappings mappings)
134 mappings))
135 #:shared-network? shared-network?
136 #:extra-file-systems %container-file-systems))
138 (file-systems (filter file-system-needed-for-boot? 137 (file-systems (filter file-system-needed-for-boot?
139 (operating-system-file-systems os))) 138 (operating-system-file-systems os)))
140 (specs (map file-system->spec file-systems))) 139 (specs (map file-system->spec file-systems)))