diff options
Diffstat (limited to 'tools/emacs-pkgs/nix-util/nix-util.el')
-rw-r--r-- | tools/emacs-pkgs/nix-util/nix-util.el | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tools/emacs-pkgs/nix-util/nix-util.el b/tools/emacs-pkgs/nix-util/nix-util.el index 533e7e6f34c9..b561ead16cf2 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 <depot> {}; 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 <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))))) + + (message "Acquiring Lisp for <depot>.%s" attribute) + (make-process :name (format "depot-nix-build/%s" attribute) + :buffer outbuf + :stderr errbuf + :sentinel build-handler + :command command))) ; TODO(tazjin): use <depot> + (provide 'nix-util) |