diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2019-07-15 16:14:31 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-07-19 11:53:47 +0200 |
| commit | bacfec8611530dc3e849fb804b51f50b299796f0 (patch) | |
| tree | 0d114dfcf5692742ade19a7dfad829b2546835a2 /gnu/system | |
| parent | b41c7beb0b5b7a16656d6acf53f77eaf2a58e125 (diff) | |
linux-container: Add 'eval/container'.
* gnu/system/linux-container.scm (eval/container): New procedure.
* tests/containers.scm ("eval/container, exit status")
("eval/container, writable user mapping"): New tests.
Diffstat (limited to 'gnu/system')
| -rw-r--r-- | gnu/system/linux-container.scm | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm index 61248c62b96..6273cee3d30 100644 --- a/gnu/system/linux-container.scm +++ b/gnu/system/linux-container.scm | |||
| @@ -35,7 +35,8 @@ | |||
| 35 | #:use-module (gnu system file-systems) | 35 | #:use-module (gnu system file-systems) |
| 36 | #:export (system-container | 36 | #:export (system-container |
| 37 | containerized-operating-system | 37 | containerized-operating-system |
| 38 | container-script)) | 38 | container-script |
| 39 | eval/container)) | ||
| 39 | 40 | ||
| 40 | (define* (container-essential-services os #:key shared-network?) | 41 | (define* (container-essential-services os #:key shared-network?) |
| 41 | "Return a list of essential services corresponding to OS, a | 42 | "Return a list of essential services corresponding to OS, a |
| @@ -205,3 +206,49 @@ that will be shared with the host system." | |||
| 205 | %namespaces))))) | 206 | %namespaces))))) |
| 206 | 207 | ||
| 207 | (gexp->script "run-container" script))) | 208 | (gexp->script "run-container" script))) |
| 209 | |||
| 210 | (define* (eval/container exp | ||
| 211 | #:key | ||
| 212 | (mappings '()) | ||
| 213 | (namespaces %namespaces)) | ||
| 214 | "Evaluate EXP, a gexp, in a new process executing in separate namespaces as | ||
| 215 | listed in NAMESPACES. Add MAPPINGS, a list of <file-system-mapping>, to the | ||
| 216 | set of directories visible in the process's mount namespace. Return the | ||
| 217 | process' exit status as a monadic value. | ||
| 218 | |||
| 219 | This is useful to implement processes that, unlike derivations, are not | ||
| 220 | entirely pure and need to access the outside world or to perform side | ||
| 221 | effects." | ||
| 222 | (mlet %store-monad ((lowered (lower-gexp exp))) | ||
| 223 | (define inputs | ||
| 224 | (cons (lowered-gexp-guile lowered) | ||
| 225 | (lowered-gexp-inputs lowered))) | ||
| 226 | |||
| 227 | (define items | ||
| 228 | (append (append-map derivation-input-output-paths inputs) | ||
| 229 | (lowered-gexp-sources lowered))) | ||
| 230 | |||
| 231 | (mbegin %store-monad | ||
| 232 | (built-derivations inputs) | ||
| 233 | (mlet %store-monad ((closure ((store-lift requisites) items))) | ||
| 234 | (return (call-with-container (map file-system-mapping->bind-mount | ||
| 235 | (append (map (lambda (item) | ||
| 236 | (file-system-mapping | ||
| 237 | (source item) | ||
| 238 | (target source))) | ||
| 239 | closure) | ||
| 240 | mappings)) | ||
| 241 | (lambda () | ||
| 242 | (apply execl | ||
| 243 | (string-append (derivation-input-output-path | ||
| 244 | (lowered-gexp-guile lowered)) | ||
| 245 | "/bin/guile") | ||
| 246 | "guile" | ||
| 247 | (append (map (lambda (directory) `("-L" ,directory)) | ||
| 248 | (lowered-gexp-load-path lowered)) | ||
| 249 | (map (lambda (directory) `("-C" ,directory)) | ||
| 250 | (lowered-gexp-load-compiled-path | ||
| 251 | lowered)) | ||
| 252 | (list "-c" | ||
| 253 | (object->string | ||
| 254 | (lowered-gexp-sexp lowered)))))))))))) | ||
