summary refs log tree commit diff
path: root/gnu/system/dmd.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-12-08 21:22:22 +0100
committerLudovic Courtès <ludo@gnu.org>2013-12-08 22:43:56 +0100
commit9b0ac8025860ac426cb1bc7fd417a27fe2bed36a (patch)
treef2a703efdddbdf89b5cd79e83739bf7f743e3b26 /gnu/system/dmd.scm
parent677078b48f649588f588c6adef0bb0aba70f7c8c (diff)
downloadguix-9b0ac8025860ac426cb1bc7fd417a27fe2bed36a.tar.gz
gnu: Populate /etc upon startup.
* gnu/packages/patches/dmd-getpw.patch: New file.
* gnu-system.am (dist_patch_DATA): Add it.
* gnu/packages/system.scm (dmd): Use it.
* gnu/system/vm.scm (system-qemu-image): Don't explicitly populate /etc;
  don't add ETC to the GC roots.
* gnu/system/dmd.scm (dmd-configuration-file): Add 'etc' parameter.
  [config]: Populate /etc from there.
Diffstat (limited to 'gnu/system/dmd.scm')
-rw-r--r--gnu/system/dmd.scm30
1 files changed, 28 insertions, 2 deletions
diff --git a/gnu/system/dmd.scm b/gnu/system/dmd.scm
index df38172def..aec7d03759 100644
--- a/gnu/system/dmd.scm
+++ b/gnu/system/dmd.scm
@@ -266,10 +266,13 @@ true, it must be a string specifying the default network gateway."
                       '())))))))
 
 
-(define (dmd-configuration-file services)
-  "Return the dmd configuration file for SERVICES."
+(define (dmd-configuration-file services etc)
+  "Return the dmd configuration file for SERVICES, that initializes /etc from
+ETC on startup."
   (define config
     `(begin
+       (use-modules (ice-9 ftw))
+
        (register-services
         ,@(map (match-lambda
                 (($ <service> documentation provision requirement
@@ -282,6 +285,29 @@ true, it must be a string specifying the default network gateway."
                     #:start ,start
                     #:stop ,stop)))
                services))
+
+       ;; /etc is a mixture of static and dynamic settings.  Here is where we
+       ;; initialize it from the static part.
+       (format #t "populating /etc from ~a...~%" ,etc)
+       (let ((rm-f (lambda (f)
+                     (false-if-exception (delete-file f)))))
+         (rm-f "/etc/static")
+         (symlink ,etc "/etc/static")
+         (for-each (lambda (file)
+                     ;; TODO: Handle 'shadow' specially so that changed
+                     ;; password aren't lost.
+                     (let ((target (string-append "/etc/" file))
+                           (source (string-append "/etc/static/" file)))
+                       (rm-f target)
+                       (symlink source target)))
+                   (scandir ,etc
+                            (lambda (file)
+                              (not (member file '("." ".."))))))
+
+         ;; Prevent ETC from being GC'd.
+         (symlink ,etc "/var/nix/gcroots/etc-directory"))
+
+       (format #t "starting services...~%")
        (for-each start ',(append-map service-provision services))))
 
   (text-file "dmd.conf" (object->string config)))