services: Add 'fstab-service-type'.

* gnu/services/base.scm (file-system->fstab-entry)
(file-systems->fstab): New procedures.
(fstab-service-type): New variable.
* gnu/services/base.scm (file-system-dmd-service): New procedure, taken
from...
(file-system-service-type): ... here.
* gnu/system.scm (essential-services): Add FSTAB-SERVICE-TYPE instance.
This commit is contained in:
Ludovic Courtès 2015-12-22 00:04:36 +01:00
parent 12d38e8d43
commit e43e84ba7a
2 changed files with 112 additions and 62 deletions

View file

@ -43,7 +43,8 @@ (define-module (gnu services base)
#:use-module (srfi srfi-26)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
#:export (root-file-system-service
#:export (fstab-service-type
root-file-system-service
file-system-service
user-unmount-service
device-mapping-service
@ -105,6 +106,48 @@ (define-module (gnu services base)
;;; File systems.
;;;
(define (file-system->fstab-entry file-system)
"Return a @file{/etc/fstab} entry for @var{file-system}."
(string-append (case (file-system-title file-system)
((label)
(string-append "LABEL=" (file-system-device file-system)))
((uuid)
(string-append
"UUID="
(uuid->string (file-system-device file-system))))
(else
(file-system-device file-system)))
"\t"
(file-system-mount-point file-system) "\t"
(file-system-type file-system) "\t"
(or (file-system-options file-system) "defaults") "\t"
;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
;; don't have anything sensible to put in there.
))
(define (file-systems->fstab file-systems)
"Return a @file{/etc} entry for an @file{fstab} describing
@var{file-systems}."
`(("fstab" ,(plain-file "fstab"
(string-append
"\
# This file was generated from your GuixSD configuration. Any changes
# will be lost upon reboot or reconfiguration.\n\n"
(string-join (map file-system->fstab-entry
file-systems)
"\n")
"\n")))))
(define fstab-service-type
;; The /etc/fstab service.
(service-type (name 'fstab)
(extensions
(list (service-extension etc-service-type
file-systems->fstab)))
(compose identity)
(extend append)))
(define %root-file-system-dmd-service
(dmd-service
(documentation "Take care of the root file system.")
@ -170,12 +213,8 @@ (define dependency->dmd-service-name
((? file-system? fs)
(file-system->dmd-service-name fs))))
(define file-system-service-type
;; TODO(?): Make this an extensible service that takes <file-system> objects
;; and returns a list of <dmd-service>.
(dmd-service-type
'file-system
(lambda (file-system)
(define (file-system-dmd-service file-system)
"Return a list containing the dmd service for @var{file-system}."
(let ((target (file-system-mount-point file-system))
(device (file-system-device file-system))
(type (file-system-type file-system))
@ -183,7 +222,7 @@ (define file-system-service-type
(check? (file-system-check? file-system))
(create? (file-system-create-mount-point? file-system))
(dependencies (file-system-dependencies file-system)))
(dmd-service
(list (dmd-service
(provision (list (file-system->dmd-service-name file-system)))
(requirement `(root-file-system
,@(map dependency->dmd-service-name dependencies)))
@ -233,7 +272,17 @@ (define file-system-service-type
#:select (check-file-system canonicalize-device-spec))
,@%default-modules))
(imported-modules `((gnu build file-systems)
,@%default-imported-modules)))))))
,@%default-imported-modules))))))
(define file-system-service-type
;; TODO(?): Make this an extensible service that takes <file-system> objects
;; and returns a list of <dmd-service>.
(service-type (name 'file-system)
(extensions
(list (service-extension dmd-root-service-type
file-system-dmd-service)
(service-extension fstab-service-type
identity)))))
(define* (file-system-service file-system)
"Return a service that mounts @var{file-system}, a @code{<file-system>}

View file

@ -299,6 +299,7 @@ (define known-fs
(operating-system-groups os))
(operating-system-skeletons os))
(operating-system-etc-service os)
(service fstab-service-type '())
(session-environment-service
(operating-system-environment-variables os))
host-name procs root-fs unmount