guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hack the (init) system!


From: Ludovic Courtès
Subject: Hack the (init) system!
Date: Thu, 03 Sep 2015 23:02:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Howdy Guix!

We’ve all been talking about it for some time: a REPL server in dmd!

This can be done by changing zero lines in dmd:

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 888e446..f39a0a4 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -46,6 +46,7 @@
             device-mapping-service
             swap-service
             user-processes-service
+            dmd-repl-service
             host-name-service
             console-keymap-service
             console-font-service
@@ -287,6 +288,34 @@ stopped before 'kill' is called."
                        #f))
              (respawn? #f)))))
 
+
+(define* (dmd-repl-service #:optional (file-name "/var/run/dmd/repl")
+                           #:key (dmd dmd))
+  "Return a service that opens a REPL for dmd.  Authorized users can connect
+to the REPL at @var{file-name}, which points to a Unix-domain socket.  This
+may be done from the command using @command{socat unix-connect:@var{file-name}
+stdio}, or from Emacs using @code{M-x geiser-connect-local}."
+  (with-monad %store-monad
+    (return (service
+             (documentation "Run a REPL service inside dmd.")
+             (provision '(dmd-repl))
+             (requirement '(root-file-system))
+             (start #~(begin
+                        (use-modules (system repl server))
+
+                        (lambda* (#:optional (file-name #$file-name))
+                          (let ((socket (make-unix-domain-server-socket
+                                         #:path file-name)))
+                            (spawn-server socket)
+                            #t))))
+             (stop #~(begin
+                       (use-modules (system repl server))
+
+                       (lambda _
+                         (stop-server-and-clients!)
+                         #f)))
+             (auto-start? #f)))))
+
 (define (host-name-service name)
   "Return a service that sets the host name to @var{name}."
   (with-monad %store-monad
Then you can do:

  deco start dmd-repl
  socat unix-connect:/var/run/dmd/repl stdio

and tinker from there.  New ways to cra^W experiment with your system!

I’m tempted to just commit that.  There are shortcomings: (1) the REPL
server runs in a thread and threads + fork don’t go together well
(although in practice dmd only does fork followed by exec, so it’s OK),
and (2) for some reason ‘stop-server-and-clients!’ seems to leave open
sockets behind it, so if you restart the REPL on the same socket, it
fails with EADDRINUSE.

Thoughts?

Ludo’.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]