From 381a859b3ba8d3c60ce38c5ba81ec08c9da03f74 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 17 Jan 2020 16:43:49 +0000 Subject: feat(emacs-pkgs/nix-util): Add nix/sly-from-depot function Adds a function that can launch Sly with a pre-configured SBCL for a Lisp derivation in the depot. This makes it convenient to spin up development environments for Lisp libraries and programs by simply calling `M-x nix/sly-from-depot RET tools.something`. This relies on `nix-depot-path` being configured currently as I have not yet reliably added the depot to my NIX_PATH on all machines. --- tools/emacs-pkgs/nix-util/nix-util.el | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/emacs-pkgs/nix-util/nix-util.el b/tools/emacs-pkgs/nix-util/nix-util.el index 533e7e6f34..b561ead16c 100644 --- a/tools/emacs-pkgs/nix-util/nix-util.el +++ b/tools/emacs-pkgs/nix-util/nix-util.el @@ -9,11 +9,13 @@ ;;; Commentary: ;; ;; This package adds some functionality that I find useful when -;; working in Nix buffers. +;; working in Nix buffers or programs installed from Nix. (require 'json) (require 'map) +(defvar nix-depot-path "/home/tazjin/depot") + (defun nix/prefetch-github (owner repo) ; TODO(tazjin): support different branches "Fetch the master branch of a GitHub repository and insert the call to `fetchFromGitHub' at point." @@ -64,4 +66,38 @@ :stderr errbuf :sentinel prefetch-handler))) +(defun nix/sly-from-depot (attribute) + "Start a Sly REPL configured with a Lisp matching a derivation + from my depot. + + The derivation invokes nix.buildLisp.sbclWith and is built + asynchronously. The build output is included in the error + thrown on build failures." + + (interactive "sAttribute: ") + (let* ((outbuf (get-buffer-create (format "*depot-out/%s*" attribute))) + (errbuf (get-buffer-create (format "*depot-errors/%s*" attribute))) + (expression (format "let depot = import {}; in depot.nix.buildLisp.sbclWith [ depot.%s ]" attribute)) + (command (list "nix-build" "-I" (format "depot=%s" nix-depot-path) "-E" expression)) + (build-handler + (lambda (process event) + (unwind-protect + (pcase event + ("finished\n" + (let* ((outpath (s-trim (with-current-buffer outbuf (buffer-string)))) + (lisp-path (s-concat outpath "/bin/sbcl"))) + (message "Acquired Lisp for .%s at %s" attribute lisp-path) + (sly lisp-path))) + (_ (with-current-buffer errbuf + (error "Failed to build '%s':\n%s" attribute (buffer-string))))) + (kill-buffer outbuf) + (kill-buffer errbuf))))) + + (message "Acquiring Lisp for .%s" attribute) + (make-process :name (format "depot-nix-build/%s" attribute) + :buffer outbuf + :stderr errbuf + :sentinel build-handler + :command command))) ; TODO(tazjin): use + (provide 'nix-util) -- cgit 1.4.1