diff options
Diffstat (limited to 'tools/emacs-pkgs/nix-util/nix-util.el')
-rw-r--r-- | tools/emacs-pkgs/nix-util/nix-util.el | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/tools/emacs-pkgs/nix-util/nix-util.el b/tools/emacs-pkgs/nix-util/nix-util.el index 533e7e6f34c9..4b9dd31a022e 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." @@ -38,7 +40,7 @@ ("finished\n" (let* ((json-string (with-current-buffer outbuf (buffer-string))) - (result (json-parse-string json-string))) + (result (json-read-from-string json-string))) (with-current-buffer buffer (goto-char point) (map-let (("rev" rev) ("sha256" sha256)) result @@ -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: ") + (lexical-let* ((outbuf (get-buffer-create (format "*depot-out/%s*" attribute))) + (errbuf (get-buffer-create (format "*depot-errors/%s*" attribute))) + (expression (format "let depot = import <depot> {}; in depot.nix.buildLisp.sbclWith [ depot.%s ]" attribute)) + ;; TODO(tazjin): use <depot> + (command (list "nix-build" "--no-out-link" "-I" (format "depot=%s" nix-depot-path) "-E" expression))) + + (message "Acquiring Lisp for <depot>.%s" attribute) + (make-process :name (format "depot-nix-build/%s" attribute) + :buffer outbuf + :stderr errbuf + :command command + :sentinel + (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 <depot>.%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)))))) + (provide 'nix-util) |