unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Hack the (init) system!
@ 2015-09-03 21:02 Ludovic Courtès
  2015-09-04  0:25 ` Thompson, David
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Ludovic Courtès @ 2015-09-03 21:02 UTC (permalink / raw)
  To: Guix-devel

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1879 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 580 bytes --]


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’.

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-09-28 15:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-03 21:02 Hack the (init) system! Ludovic Courtès
2015-09-04  0:25 ` Thompson, David
2015-09-04 12:05   ` Ludovic Courtès
2015-09-04 13:05     ` Thompson, David
2015-09-04  0:54 ` Thompson, David
2015-09-04  1:57 ` Mark H Weaver
2015-09-04 12:08   ` Ludovic Courtès
2015-09-25 23:04     ` Christopher Allan Webber
2015-09-26 13:02       ` Ludovic Courtès
2015-09-26 17:30         ` Christopher Allan Webber
2015-09-28  9:13       ` Andy Wingo
2015-09-28 13:42         ` Taylan Ulrich Bayırlı/Kammer
2015-09-28 13:43         ` Thompson, David
2015-09-28 15:01         ` Christopher Allan Webber

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).