diff options
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/services/base.scm | 105 | ||||
| -rw-r--r-- | gnu/services/shepherd.scm | 43 | ||||
| -rw-r--r-- | gnu/system/mapped-devices.scm | 34 | ||||
| -rw-r--r-- | gnu/tests.scm | 122 |
4 files changed, 144 insertions, 160 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index d9c60778a1c..02e3b419042 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -229,59 +229,58 @@ FILE-SYSTEM." | |||
| 229 | (create? (file-system-create-mount-point? file-system)) | 229 | (create? (file-system-create-mount-point? file-system)) |
| 230 | (dependencies (file-system-dependencies file-system))) | 230 | (dependencies (file-system-dependencies file-system))) |
| 231 | (if (file-system-mount? file-system) | 231 | (if (file-system-mount? file-system) |
| 232 | (list | 232 | (with-imported-modules '((gnu build file-systems) |
| 233 | (shepherd-service | 233 | (guix build bournish)) |
| 234 | (provision (list (file-system->shepherd-service-name file-system))) | 234 | (list |
| 235 | (requirement `(root-file-system | 235 | (shepherd-service |
| 236 | ,@(map dependency->shepherd-service-name dependencies))) | 236 | (provision (list (file-system->shepherd-service-name file-system))) |
| 237 | (documentation "Check, mount, and unmount the given file system.") | 237 | (requirement `(root-file-system |
| 238 | (start #~(lambda args | 238 | ,@(map dependency->shepherd-service-name dependencies))) |
| 239 | ;; FIXME: Use or factorize with 'mount-file-system'. | 239 | (documentation "Check, mount, and unmount the given file system.") |
| 240 | (let ((device (canonicalize-device-spec #$device '#$title)) | 240 | (start #~(lambda args |
| 241 | (flags #$(mount-flags->bit-mask | 241 | ;; FIXME: Use or factorize with 'mount-file-system'. |
| 242 | (file-system-flags file-system)))) | 242 | (let ((device (canonicalize-device-spec #$device '#$title)) |
| 243 | #$(if create? | 243 | (flags #$(mount-flags->bit-mask |
| 244 | #~(mkdir-p #$target) | 244 | (file-system-flags file-system)))) |
| 245 | #~#t) | 245 | #$(if create? |
| 246 | #$(if check? | 246 | #~(mkdir-p #$target) |
| 247 | #~(begin | 247 | #~#t) |
| 248 | ;; Make sure fsck.ext2 & co. can be found. | 248 | #$(if check? |
| 249 | (setenv "PATH" | 249 | #~(begin |
| 250 | (string-append | 250 | ;; Make sure fsck.ext2 & co. can be found. |
| 251 | #$e2fsprogs "/sbin:" | 251 | (setenv "PATH" |
| 252 | "/run/current-system/profile/sbin:" | 252 | (string-append |
| 253 | (getenv "PATH"))) | 253 | #$e2fsprogs "/sbin:" |
| 254 | (check-file-system device #$type)) | 254 | "/run/current-system/profile/sbin:" |
| 255 | #~#t) | 255 | (getenv "PATH"))) |
| 256 | 256 | (check-file-system device #$type)) | |
| 257 | (mount device #$target #$type flags | 257 | #~#t) |
| 258 | #$(file-system-options file-system)) | 258 | |
| 259 | 259 | (mount device #$target #$type flags | |
| 260 | ;; For read-only bind mounts, an extra remount is | 260 | #$(file-system-options file-system)) |
| 261 | ;; needed, as per <http://lwn.net/Articles/281157/>, | 261 | |
| 262 | ;; which still applies to Linux 4.0. | 262 | ;; For read-only bind mounts, an extra remount is |
| 263 | (when (and (= MS_BIND (logand flags MS_BIND)) | 263 | ;; needed, as per <http://lwn.net/Articles/281157/>, |
| 264 | (= MS_RDONLY (logand flags MS_RDONLY))) | 264 | ;; which still applies to Linux 4.0. |
| 265 | (mount device #$target #$type | 265 | (when (and (= MS_BIND (logand flags MS_BIND)) |
| 266 | (logior MS_BIND MS_REMOUNT MS_RDONLY)))) | 266 | (= MS_RDONLY (logand flags MS_RDONLY))) |
| 267 | #t)) | 267 | (mount device #$target #$type |
| 268 | (stop #~(lambda args | 268 | (logior MS_BIND MS_REMOUNT MS_RDONLY)))) |
| 269 | ;; Normally there are no processes left at this point, so | 269 | #t)) |
| 270 | ;; TARGET can be safely unmounted. | 270 | (stop #~(lambda args |
| 271 | 271 | ;; Normally there are no processes left at this point, so | |
| 272 | ;; Make sure PID 1 doesn't keep TARGET busy. | 272 | ;; TARGET can be safely unmounted. |
| 273 | (chdir "/") | 273 | |
| 274 | 274 | ;; Make sure PID 1 doesn't keep TARGET busy. | |
| 275 | (umount #$target) | 275 | (chdir "/") |
| 276 | #f)) | 276 | |
| 277 | 277 | (umount #$target) | |
| 278 | ;; We need an additional module. | 278 | #f)) |
| 279 | (modules `(((gnu build file-systems) | 279 | |
| 280 | #:select (check-file-system canonicalize-device-spec)) | 280 | ;; We need an additional module. |
| 281 | ,@%default-modules)) | 281 | (modules `(((gnu build file-systems) |
| 282 | (imported-modules `((gnu build file-systems) | 282 | #:select (check-file-system canonicalize-device-spec)) |
| 283 | (guix build bournish) | 283 | ,@%default-modules))))) |
| 284 | ,@%default-imported-modules)))) | ||
| 285 | '()))) | 284 | '()))) |
| 286 | 285 | ||
| 287 | (define file-system-service-type | 286 | (define file-system-service-type |
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index 5d829e4c38e..f35a6bf10aa 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm | |||
| @@ -47,9 +47,7 @@ | |||
| 47 | shepherd-service-stop | 47 | shepherd-service-stop |
| 48 | shepherd-service-auto-start? | 48 | shepherd-service-auto-start? |
| 49 | shepherd-service-modules | 49 | shepherd-service-modules |
| 50 | shepherd-service-imported-modules | ||
| 51 | 50 | ||
| 52 | %default-imported-modules | ||
| 53 | %default-modules | 51 | %default-modules |
| 54 | 52 | ||
| 55 | shepherd-service-file | 53 | shepherd-service-file |
| @@ -138,9 +136,7 @@ for a service that extends SHEPHERD-ROOT-SERVICE-TYPE and nothing else." | |||
| 138 | (auto-start? shepherd-service-auto-start? ;Boolean | 136 | (auto-start? shepherd-service-auto-start? ;Boolean |
| 139 | (default #t)) | 137 | (default #t)) |
| 140 | (modules shepherd-service-modules ;list of module names | 138 | (modules shepherd-service-modules ;list of module names |
| 141 | (default %default-modules)) | 139 | (default %default-modules))) |
| 142 | (imported-modules shepherd-service-imported-modules ;list of module names | ||
| 143 | (default %default-imported-modules))) | ||
| 144 | 140 | ||
| 145 | (define (shepherd-service-canonical-name service) | 141 | (define (shepherd-service-canonical-name service) |
| 146 | "Return the 'canonical name' of SERVICE." | 142 | "Return the 'canonical name' of SERVICE." |
| @@ -203,37 +199,26 @@ stored." | |||
| 203 | (define (shepherd-service-file service) | 199 | (define (shepherd-service-file service) |
| 204 | "Return a file defining SERVICE." | 200 | "Return a file defining SERVICE." |
| 205 | (gexp->file (shepherd-service-file-name service) | 201 | (gexp->file (shepherd-service-file-name service) |
| 206 | #~(begin | 202 | (with-imported-modules %default-imported-modules |
| 207 | (use-modules #$@(shepherd-service-modules service)) | 203 | #~(begin |
| 208 | 204 | (use-modules #$@(shepherd-service-modules service)) | |
| 209 | (make <service> | 205 | |
| 210 | #:docstring '#$(shepherd-service-documentation service) | 206 | (make <service> |
| 211 | #:provides '#$(shepherd-service-provision service) | 207 | #:docstring '#$(shepherd-service-documentation service) |
| 212 | #:requires '#$(shepherd-service-requirement service) | 208 | #:provides '#$(shepherd-service-provision service) |
| 213 | #:respawn? '#$(shepherd-service-respawn? service) | 209 | #:requires '#$(shepherd-service-requirement service) |
| 214 | #:start #$(shepherd-service-start service) | 210 | #:respawn? '#$(shepherd-service-respawn? service) |
| 215 | #:stop #$(shepherd-service-stop service))))) | 211 | #:start #$(shepherd-service-start service) |
| 212 | #:stop #$(shepherd-service-stop service)))))) | ||
| 216 | 213 | ||
| 217 | (define (shepherd-configuration-file services) | 214 | (define (shepherd-configuration-file services) |
| 218 | "Return the shepherd configuration file for SERVICES." | 215 | "Return the shepherd configuration file for SERVICES." |
| 219 | (define modules | ||
| 220 | (delete-duplicates | ||
| 221 | (append-map shepherd-service-imported-modules services))) | ||
| 222 | |||
| 223 | (assert-valid-graph services) | 216 | (assert-valid-graph services) |
| 224 | 217 | ||
| 225 | (mlet %store-monad ((modules (imported-modules modules)) | 218 | (mlet %store-monad ((files (mapm %store-monad |
| 226 | (compiled (compiled-modules modules)) | 219 | shepherd-service-file services))) |
| 227 | (files (mapm %store-monad | ||
| 228 | shepherd-service-file | ||
| 229 | services))) | ||
| 230 | (define config | 220 | (define config |
| 231 | #~(begin | 221 | #~(begin |
| 232 | (eval-when (expand load eval) | ||
| 233 | (set! %load-path (cons #$modules %load-path)) | ||
| 234 | (set! %load-compiled-path | ||
| 235 | (cons #$compiled %load-compiled-path))) | ||
| 236 | |||
| 237 | (use-modules (srfi srfi-34) | 222 | (use-modules (srfi srfi-34) |
| 238 | (system repl error-handling)) | 223 | (system repl error-handling)) |
| 239 | 224 | ||
diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm index 450b4737acc..732f73cc4ba 100644 --- a/gnu/system/mapped-devices.scm +++ b/gnu/system/mapped-devices.scm | |||
| @@ -85,9 +85,7 @@ | |||
| 85 | (modules `((rnrs bytevectors) ;bytevector? | 85 | (modules `((rnrs bytevectors) ;bytevector? |
| 86 | ((gnu build file-systems) | 86 | ((gnu build file-systems) |
| 87 | #:select (find-partition-by-luks-uuid)) | 87 | #:select (find-partition-by-luks-uuid)) |
| 88 | ,@%default-modules)) | 88 | ,@%default-modules))))))) |
| 89 | (imported-modules `((gnu build file-systems) | ||
| 90 | ,@%default-imported-modules))))))) | ||
| 91 | 89 | ||
| 92 | (define (device-mapping-service mapped-device) | 90 | (define (device-mapping-service mapped-device) |
| 93 | "Return a service that sets up @var{mapped-device}." | 91 | "Return a service that sets up @var{mapped-device}." |
| @@ -101,20 +99,22 @@ | |||
| 101 | (define (open-luks-device source target) | 99 | (define (open-luks-device source target) |
| 102 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using | 100 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using |
| 103 | 'cryptsetup'." | 101 | 'cryptsetup'." |
| 104 | #~(let ((source #$source)) | 102 | (with-imported-modules '((gnu build file-systems) |
| 105 | (zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") | 103 | (guix build bournish)) |
| 106 | "open" "--type" "luks" | 104 | #~(let ((source #$source)) |
| 107 | 105 | (zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") | |
| 108 | ;; Note: We cannot use the "UUID=source" syntax here | 106 | "open" "--type" "luks" |
| 109 | ;; because 'cryptsetup' implements it by searching the | 107 | |
| 110 | ;; udev-populated /dev/disk/by-id directory but udev may | 108 | ;; Note: We cannot use the "UUID=source" syntax here |
| 111 | ;; be unavailable at the time we run this. | 109 | ;; because 'cryptsetup' implements it by searching the |
| 112 | (if (bytevector? source) | 110 | ;; udev-populated /dev/disk/by-id directory but udev may |
| 113 | (or (find-partition-by-luks-uuid source) | 111 | ;; be unavailable at the time we run this. |
| 114 | (error "LUKS partition not found" source)) | 112 | (if (bytevector? source) |
| 115 | source) | 113 | (or (find-partition-by-luks-uuid source) |
| 116 | 114 | (error "LUKS partition not found" source)) | |
| 117 | #$target)))) | 115 | source) |
| 116 | |||
| 117 | #$target))))) | ||
| 118 | 118 | ||
| 119 | (define (close-luks-device source target) | 119 | (define (close-luks-device source target) |
| 120 | "Return a gexp that closes TARGET, a LUKS device." | 120 | "Return a gexp that closes TARGET, a LUKS device." |
diff --git a/gnu/tests.scm b/gnu/tests.scm index 1821ac45c55..8abe6c608ba 100644 --- a/gnu/tests.scm +++ b/gnu/tests.scm | |||
| @@ -80,68 +80,68 @@ | |||
| 80 | (srfi srfi-9 gnu) | 80 | (srfi srfi-9 gnu) |
| 81 | (guix build syscalls) | 81 | (guix build syscalls) |
| 82 | (rnrs bytevectors))) | 82 | (rnrs bytevectors))) |
| 83 | (imported-modules `((guix build syscalls) | ||
| 84 | ,@imported-modules)) | ||
| 85 | (start | 83 | (start |
| 86 | #~(lambda () | 84 | (with-imported-modules `((guix build syscalls) |
| 87 | (define (clear-echo termios) | 85 | ,@imported-modules) |
| 88 | (set-field termios (termios-local-flags) | 86 | #~(lambda () |
| 89 | (logand (lognot (local-flags ECHO)) | 87 | (define (clear-echo termios) |
| 90 | (termios-local-flags termios)))) | 88 | (set-field termios (termios-local-flags) |
| 91 | 89 | (logand (lognot (local-flags ECHO)) | |
| 92 | (define (self-quoting? x) | 90 | (termios-local-flags termios)))) |
| 93 | (letrec-syntax ((one-of (syntax-rules () | 91 | |
| 94 | ((_) #f) | 92 | (define (self-quoting? x) |
| 95 | ((_ pred rest ...) | 93 | (letrec-syntax ((one-of (syntax-rules () |
| 96 | (or (pred x) | 94 | ((_) #f) |
| 97 | (one-of rest ...)))))) | 95 | ((_ pred rest ...) |
| 98 | (one-of symbol? string? pair? null? vector? | 96 | (or (pred x) |
| 99 | bytevector? number? boolean?))) | 97 | (one-of rest ...)))))) |
| 100 | 98 | (one-of symbol? string? pair? null? vector? | |
| 101 | (match (primitive-fork) | 99 | bytevector? number? boolean?))) |
| 102 | (0 | 100 | |
| 103 | (dynamic-wind | 101 | (match (primitive-fork) |
| 104 | (const #t) | 102 | (0 |
| 105 | (lambda () | 103 | (dynamic-wind |
| 106 | (let* ((repl (open-file #$device "r+0")) | 104 | (const #t) |
| 107 | (termios (tcgetattr (fileno repl))) | 105 | (lambda () |
| 108 | (console (open-file "/dev/console" "r+0"))) | 106 | (let* ((repl (open-file #$device "r+0")) |
| 109 | ;; Don't echo input back. | 107 | (termios (tcgetattr (fileno repl))) |
| 110 | (tcsetattr (fileno repl) (tcsetattr-action TCSANOW) | 108 | (console (open-file "/dev/console" "r+0"))) |
| 111 | (clear-echo termios)) | 109 | ;; Don't echo input back. |
| 112 | 110 | (tcsetattr (fileno repl) (tcsetattr-action TCSANOW) | |
| 113 | ;; Redirect output to the console. | 111 | (clear-echo termios)) |
| 114 | (close-fdes 1) | 112 | |
| 115 | (close-fdes 2) | 113 | ;; Redirect output to the console. |
| 116 | (dup2 (fileno console) 1) | 114 | (close-fdes 1) |
| 117 | (dup2 (fileno console) 2) | 115 | (close-fdes 2) |
| 118 | (close-port console) | 116 | (dup2 (fileno console) 1) |
| 119 | 117 | (dup2 (fileno console) 2) | |
| 120 | (display 'ready repl) | 118 | (close-port console) |
| 121 | (let loop () | 119 | |
| 122 | (newline repl) | 120 | (display 'ready repl) |
| 123 | 121 | (let loop () | |
| 124 | (match (read repl) | 122 | (newline repl) |
| 125 | ((? eof-object?) | 123 | |
| 126 | (primitive-exit 0)) | 124 | (match (read repl) |
| 127 | (expr | 125 | ((? eof-object?) |
| 128 | (catch #t | 126 | (primitive-exit 0)) |
| 129 | (lambda () | 127 | (expr |
| 130 | (let ((result (primitive-eval expr))) | 128 | (catch #t |
| 131 | (write (if (self-quoting? result) | 129 | (lambda () |
| 132 | result | 130 | (let ((result (primitive-eval expr))) |
| 133 | (object->string result)) | 131 | (write (if (self-quoting? result) |
| 134 | repl))) | 132 | result |
| 135 | (lambda (key . args) | 133 | (object->string result)) |
| 136 | (print-exception (current-error-port) | 134 | repl))) |
| 137 | (stack-ref (make-stack #t) 1) | 135 | (lambda (key . args) |
| 138 | key args) | 136 | (print-exception (current-error-port) |
| 139 | (write #f repl))))) | 137 | (stack-ref (make-stack #t) 1) |
| 140 | (loop)))) | 138 | key args) |
| 141 | (lambda () | 139 | (write #f repl))))) |
| 142 | (primitive-exit 1)))) | 140 | (loop)))) |
| 143 | (pid | 141 | (lambda () |
| 144 | pid)))) | 142 | (primitive-exit 1)))) |
| 143 | (pid | ||
| 144 | pid))))) | ||
| 145 | (stop #~(make-kill-destructor))))))) | 145 | (stop #~(make-kill-destructor))))))) |
| 146 | 146 | ||
| 147 | (define marionette-service-type | 147 | (define marionette-service-type |
