summaryrefslogtreecommitdiff
path: root/gnu/system/linux-container.scm
diff options
context:
space:
mode:
authorLeo Nikkilä <hello@lnikki.la>2024-01-17 23:48:35 +0200
committerLudovic Courtès <ludo@gnu.org>2024-02-05 22:29:45 +0100
commit841fd4880a03d04bf20cc51fcc1a4c956d28d74c (patch)
treed322649f610feed1651994e00facfdcff7001681 /gnu/system/linux-container.scm
parent14210b7f58ad76605fa9859395a1b57666a5c7c4 (diff)
linux-container: Inherit essential services.
Currently it's not possible to set `essential-services' when building operating systems for containers, since `container-essential-services' always uses the defaults. It's possible to reference `essential-services' from the operating system that's passed in, but since it's thunked, the operating system needs to be defined in two passes to avoid an infinite loop. * gnu/system/linux-container.scm (container-essential-services): Use operating-system-essential-services instead of the defaults to allow overriding the base services. (containerized-operating-system): Update accordingly. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Change-Id: I81452487ef1ad01d3fa874c26d93a67d58ce6062
Diffstat (limited to 'gnu/system/linux-container.scm')
-rw-r--r--gnu/system/linux-container.scm88
1 files changed, 47 insertions, 41 deletions
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index 485baea4c55..c780b68fba4 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -6,6 +6,7 @@
6;;; Copyright © 2020 Google LLC 6;;; Copyright © 2020 Google LLC
7;;; Copyright © 2022 Ricardo Wurmus <rekado@elephly.net> 7;;; Copyright © 2022 Ricardo Wurmus <rekado@elephly.net>
8;;; Copyright © 2023 Pierre Langlois <pierre.langlois@gmx.com> 8;;; Copyright © 2023 Pierre Langlois <pierre.langlois@gmx.com>
9;;; Copyright © 2024 Leo Nikkilä <hello@lnikki.la>
9;;; 10;;;
10;;; This file is part of GNU Guix. 11;;; This file is part of GNU Guix.
11;;; 12;;;
@@ -56,7 +57,7 @@ from OS that are needed on the bare metal and not in a container."
56 (if shared-network? 57 (if shared-network?
57 (list hosts-service-type) 58 (list hosts-service-type)
58 '())))) 59 '()))))
59 (operating-system-default-essential-services os))) 60 (operating-system-essential-services os)))
60 61
61 (cons (service system-service-type 62 (cons (service system-service-type
62 `(("locale" ,(operating-system-locale-directory os)))) 63 `(("locale" ,(operating-system-locale-directory os))))
@@ -144,48 +145,53 @@ containerized OS. EXTRA-FILE-SYSTEMS is a list of file systems to add to OS."
144 (list (service dummy-networking-service-type)) 145 (list (service dummy-networking-service-type))
145 '())) 146 '()))
146 147
148 (define os-with-base-essential-services
149 (operating-system
150 (inherit os)
151 (swap-devices '()) ; disable swap
152 (services
153 (append services-to-add
154 (filter-map (lambda (s)
155 (cond ((memq (service-kind s) services-to-drop)
156 #f)
157 ((eq? nscd-service-type (service-kind s))
158 (service nscd-service-type
159 (nscd-configuration
160 (inherit (service-value s))
161 (caches %nscd-container-caches))))
162 ((eq? guix-service-type (service-kind s))
163 ;; Pass '--disable-chroot' so that
164 ;; guix-daemon can build thing even in
165 ;; Docker without '--privileged'.
166 (service guix-service-type
167 (guix-configuration
168 (inherit (service-value s))
169 (extra-options
170 (cons "--disable-chroot"
171 (guix-configuration-extra-options
172 (service-value s)))))))
173 (else s)))
174 (operating-system-user-services os))))
175 (file-systems (append (map mapping->fs
176 (if shared-network?
177 (append %network-file-mappings mappings)
178 mappings))
179 extra-file-systems
180 user-file-systems
181
182 ;; Provide a dummy root file system so we can create
183 ;; a 'boot-parameters' file.
184 (list (file-system
185 (mount-point "/")
186 (device "nothing")
187 (type "dummy")))))))
188
189 ;; `essential-services' is thunked, we need to evaluate it separately.
147 (operating-system 190 (operating-system
148 (inherit os) 191 (inherit os-with-base-essential-services)
149 (swap-devices '()) ; disable swap
150 (essential-services (container-essential-services 192 (essential-services (container-essential-services
151 this-operating-system 193 os-with-base-essential-services
152 #:shared-network? shared-network?)) 194 #:shared-network? shared-network?))))
153 (services
154 (append services-to-add
155 (filter-map (lambda (s)
156 (cond ((memq (service-kind s) services-to-drop)
157 #f)
158 ((eq? nscd-service-type (service-kind s))
159 (service nscd-service-type
160 (nscd-configuration
161 (inherit (service-value s))
162 (caches %nscd-container-caches))))
163 ((eq? guix-service-type (service-kind s))
164 ;; Pass '--disable-chroot' so that
165 ;; guix-daemon can build thing even in
166 ;; Docker without '--privileged'.
167 (service guix-service-type
168 (guix-configuration
169 (inherit (service-value s))
170 (extra-options
171 (cons "--disable-chroot"
172 (guix-configuration-extra-options
173 (service-value s)))))))
174 (else s)))
175 (operating-system-user-services os))))
176 (file-systems (append (map mapping->fs
177 (if shared-network?
178 (append %network-file-mappings mappings)
179 mappings))
180 extra-file-systems
181 user-file-systems
182
183 ;; Provide a dummy root file system so we can create
184 ;; a 'boot-parameters' file.
185 (list (file-system
186 (mount-point "/")
187 (device "nothing")
188 (type "dummy")))))))
189 195
190(define* (container-script os #:key (mappings '()) shared-network?) 196(define* (container-script os #:key (mappings '()) shared-network?)
191 "Return a derivation of a script that runs OS as a Linux container. 197 "Return a derivation of a script that runs OS as a Linux container.