summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-02-08 15:32:28 +0100
committerLudovic Courtès <ludo@gnu.org>2017-02-08 16:17:05 +0100
commit387e175492f960d7d86f34f3b2e43938fa72dbf3 (patch)
treea12082201befe64989049c1c417752195f0381be /gnu
parent618739b063dd0f8f33d0618cf64567aaaf86f4d7 (diff)
services: Add 'special-files-service-type'.
* gnu/build/activation.scm (activate-/bin/sh): Remove. (activate-special-files): New procedure. * gnu/services.scm (activation-script): Remove call to 'activate-/bin/sh'. (special-files-service-type): New variable. (extra-special-file): New procedure. * gnu/services/base.scm (%base-services): Add SPECIAL-FILES-SERVICE-TYPE instance. * gnu/tests/base.scm (run-basic-test)[special-files]: New variables. ["special files"]: New test.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/build/activation.scm23
-rw-r--r--gnu/services.scm25
-rw-r--r--gnu/services/base.scm7
-rw-r--r--gnu/tests/base.scm17
4 files changed, 62 insertions, 10 deletions
diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm
index e58304e83b1..c4ed40e0deb 100644
--- a/gnu/build/activation.scm
+++ b/gnu/build/activation.scm
@@ -28,7 +28,7 @@
28 activate-user-home 28 activate-user-home
29 activate-etc 29 activate-etc
30 activate-setuid-programs 30 activate-setuid-programs
31 activate-/bin/sh 31 activate-special-files
32 activate-modprobe 32 activate-modprobe
33 activate-firmware 33 activate-firmware
34 activate-ptrace-attach 34 activate-ptrace-attach
@@ -383,10 +383,23 @@ copy SOURCE to TARGET."
383 383
384 (for-each make-setuid-program programs)) 384 (for-each make-setuid-program programs))
385 385
386(define (activate-/bin/sh shell) 386(define (activate-special-files special-files)
387 "Change /bin/sh to point to SHELL." 387 "Install the files listed in SPECIAL-FILES. Each element of SPECIAL-FILES
388 (symlink shell "/bin/sh.new") 388is a pair where the first element is the name of the special file and the
389 (rename-file "/bin/sh.new" "/bin/sh")) 389second element is the name it should appear at, such as:
390
391 ((\"/bin/sh\" \"/gnu/store/…-bash/bin/sh\")
392 (\"/usr/bin/env\" \"/gnu/store/…-coreutils/bin/env\"))
393"
394 (define install-special-file
395 (match-lambda
396 ((target file)
397 (let ((pivot (string-append target ".new")))
398 (mkdir-p (dirname target))
399 (symlink file pivot)
400 (rename-file pivot target)))))
401
402 (for-each install-special-file special-files))
390 403
391(define (activate-modprobe modprobe) 404(define (activate-modprobe modprobe)
392 "Tell the kernel to use MODPROBE to load modules." 405 "Tell the kernel to use MODPROBE to load modules."
diff --git a/gnu/services.scm b/gnu/services.scm
index e645889d30b..6ac4f1322d2 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -72,6 +72,8 @@
72 activation-service-type 72 activation-service-type
73 activation-service->script 73 activation-service->script
74 %linux-bare-metal-service 74 %linux-bare-metal-service
75 special-files-service-type
76 extra-special-file
75 etc-service-type 77 etc-service-type
76 etc-directory 78 etc-directory
77 setuid-program-service-type 79 setuid-program-service-type
@@ -336,10 +338,6 @@ ACTIVATION-SCRIPT-TYPE."
336 #~(begin 338 #~(begin
337 (use-modules (gnu build activation)) 339 (use-modules (gnu build activation))
338 340
339 ;; Make sure /bin/sh is valid and current.
340 (activate-/bin/sh
341 (string-append #$(canonical-package bash) "/bin/sh"))
342
343 ;; Make sure the user accounting database exists. If it 341 ;; Make sure the user accounting database exists. If it
344 ;; does not exist, 'setutxent' does not create it and 342 ;; does not exist, 'setutxent' does not create it and
345 ;; thus there is no accounting at all. 343 ;; thus there is no accounting at all.
@@ -413,6 +411,25 @@ ACTIVATION-SCRIPT-TYPE."
413 ;; necessary or impossible in a container. 411 ;; necessary or impossible in a container.
414 (service linux-bare-metal-service-type #f)) 412 (service linux-bare-metal-service-type #f))
415 413
414(define special-files-service-type
415 ;; Service to install "special files" such as /bin/sh and /usr/bin/env.
416 (service-type
417 (name 'special-files)
418 (extensions
419 (list (service-extension activation-service-type
420 (lambda (files)
421 #~(activate-special-files '#$files)))))
422 (compose concatenate)
423 (extend append)))
424
425(define (extra-special-file file target)
426 "Use TARGET as the \"special file\" FILE. For example, TARGET might be
427 (file-append coreutils \"/bin/env\")
428and FILE could be \"/usr/bin/env\"."
429 (simple-service (string->symbol (string-append "special-file-" file))
430 special-files-service-type
431 `((,file ,target))))
432
416(define (etc-directory service) 433(define (etc-directory service)
417 "Return the directory for SERVICE, a service of type ETC-SERVICE-TYPE." 434 "Return the directory for SERVICE, a service of type ETC-SERVICE-TYPE."
418 (files->etc-directory (service-parameters service))) 435 (files->etc-directory (service-parameters service)))
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index d9f3a1445e0..57601eab85d 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -36,6 +36,7 @@
36 #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools)) 36 #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools))
37 #:use-module ((gnu packages base) 37 #:use-module ((gnu packages base)
38 #:select (canonical-package glibc)) 38 #:select (canonical-package glibc))
39 #:use-module (gnu packages bash)
39 #:use-module (gnu packages package-management) 40 #:use-module (gnu packages package-management)
40 #:use-module (gnu packages lsof) 41 #:use-module (gnu packages lsof)
41 #:use-module (gnu packages terminals) 42 #:use-module (gnu packages terminals)
@@ -1558,6 +1559,10 @@ This service is not part of @var{%base-services}."
1558 ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is 1559 ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is
1559 ;; used, so enable them by default. The FUSE and ALSA rules are 1560 ;; used, so enable them by default. The FUSE and ALSA rules are
1560 ;; less critical, but handy. 1561 ;; less critical, but handy.
1561 (udev-service #:rules (list lvm2 fuse alsa-utils crda)))) 1562 (udev-service #:rules (list lvm2 fuse alsa-utils crda))
1563
1564 (service special-files-service-type
1565 `(("/bin/sh" ,(file-append (canonical-package bash)
1566 "/bin/sh"))))))
1562 1567
1563;;; base.scm ends here 1568;;; base.scm ends here
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index 8a6a7a15688..000a4ddecbe 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -77,6 +77,11 @@ When INITIALIZATION is true, it must be a one-argument procedure that is
77passed a gexp denoting the marionette, and it must return gexp that is 77passed a gexp denoting the marionette, and it must return gexp that is
78inserted before the first test. This is used to introduce an extra 78inserted before the first test. This is used to introduce an extra
79initialization step, such as entering a LUKS passphrase." 79initialization step, such as entering a LUKS passphrase."
80 (define special-files
81 (service-parameters
82 (fold-services (operating-system-services os)
83 #:target-type special-files-service-type)))
84
80 (define test 85 (define test
81 (with-imported-modules '((gnu build marionette) 86 (with-imported-modules '((gnu build marionette)
82 (guix build syscalls)) 87 (guix build syscalls))
@@ -120,6 +125,18 @@ grep --version
120info --version") 125info --version")
121 marionette))) 126 marionette)))
122 127
128 (test-equal "special files"
129 '#$special-files
130 (marionette-eval
131 '(begin
132 (use-modules (ice-9 match))
133
134 (map (match-lambda
135 ((file target)
136 (list file (readlink file))))
137 '#$special-files))
138 marionette))
139
123 (test-assert "accounts" 140 (test-assert "accounts"
124 (let ((users (marionette-eval '(begin 141 (let ((users (marionette-eval '(begin
125 (use-modules (ice-9 match)) 142 (use-modules (ice-9 match))