From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Hack the (init) system! Date: Thu, 03 Sep 2015 23:02:45 +0200 Message-ID: <87oahjz05m.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXbel-0006Vg-3k for Guix-devel@gnu.org; Thu, 03 Sep 2015 17:02:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXbeh-0003hB-TP for Guix-devel@gnu.org; Thu, 03 Sep 2015 17:02:51 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXbeh-0003h0-Qw for Guix-devel@gnu.org; Thu, 03 Sep 2015 17:02:47 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:53077 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZXbeg-000710-W4 for Guix-devel@gnu.org; Thu, 03 Sep 2015 17:02:47 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Guix-devel --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Howdy Guix! We=E2=80=99ve all been talking about it for some time: a REPL server in dmd! This can be done by changing zero lines in dmd: --=-=-= Content-Type: text/x-patch Content-Disposition: inline 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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=E2=80=99m tempted to just commit that. There are shortcomings: (1) the R= EPL server runs in a thread and threads + fork don=E2=80=99t go together well (although in practice dmd only does fork followed by exec, so it=E2=80=99s = OK), and (2) for some reason =E2=80=98stop-server-and-clients!=E2=80=99 seems to= leave open sockets behind it, so if you restart the REPL on the same socket, it fails with EADDRINUSE. Thoughts? Ludo=E2=80=99. --=-=-=--