2018-09-04 21:00:18 +02:00
|
|
|
;;; wpc-nix.el --- Nix support -*- lexical-binding: t -*-
|
2020-08-31 16:57:34 +02:00
|
|
|
|
2018-09-04 21:00:18 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-08-31 16:57:34 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "25.1"))
|
|
|
|
;; Homepage: https://user.git.corp.google.com/wpcarro/briefcase
|
2018-09-04 21:00:18 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Configuration to support working with Nix.
|
|
|
|
|
2020-08-31 15:09:24 +02:00
|
|
|
;;; Code:
|
|
|
|
|
2020-01-23 23:02:13 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-04-02 15:50:53 +02:00
|
|
|
(require 'device)
|
2020-08-25 15:19:19 +02:00
|
|
|
(require 'constants)
|
2020-01-23 23:02:13 +01:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2018-09-04 21:00:18 +02:00
|
|
|
(use-package nix-mode
|
|
|
|
:mode "\\.nix\\'")
|
|
|
|
|
2020-03-04 20:25:13 +01:00
|
|
|
;; TODO(wpcarro): Ensure the sub-process can resolve <briefcase>.
|
2020-08-31 15:09:24 +02:00
|
|
|
(defun wpc-nix-rebuild-emacs ()
|
2020-02-02 14:45:06 +01:00
|
|
|
"Use nix-env to rebuild wpcarros-emacs."
|
|
|
|
(interactive)
|
2020-09-07 16:47:17 +02:00
|
|
|
(let* ((pname (format "nix-build <briefcase/emacs.nixos>"))
|
2020-04-02 15:50:53 +02:00
|
|
|
(bname (format "*%s*" pname)))
|
|
|
|
(start-process pname bname
|
|
|
|
"nix-env"
|
2020-09-01 11:17:43 +02:00
|
|
|
"-I" (format "briefcase=%s" constants-briefcase)
|
2020-09-07 16:47:17 +02:00
|
|
|
"-f" "<briefcase>" "-iA" "emacs.nixos")
|
2020-04-02 15:50:53 +02:00
|
|
|
(display-buffer bname)))
|
2020-02-02 14:45:06 +01:00
|
|
|
|
2020-08-31 15:09:24 +02:00
|
|
|
(defun wpc-nix-sly-from-briefcase (attr)
|
|
|
|
"Start a Sly REPL configured using the derivation pointed at by ATTR.
|
2020-01-23 23:02:13 +01:00
|
|
|
|
2020-08-31 15:09:24 +02:00
|
|
|
The derivation invokes nix.buildLisp.sbclWith and is built asynchronously.
|
|
|
|
The build output is included in the error thrown on build failures."
|
2020-01-23 23:02:13 +01:00
|
|
|
(interactive "sAttribute: ")
|
2020-08-31 15:09:24 +02:00
|
|
|
(lexical-let* ((outbuf (get-buffer-create (format "*briefcase-out/%s*" attr)))
|
|
|
|
(errbuf (get-buffer-create (format "*briefcase-errors/%s*" attr)))
|
|
|
|
(expression (format "let briefcase = import <briefcase> {}; in briefcase.third_party.depot.nix.buildLisp.sbclWith [ briefcase.%s ]" attr))
|
2020-01-23 23:02:13 +01:00
|
|
|
(command (list "nix-build" "-E" expression)))
|
2020-08-31 15:09:24 +02:00
|
|
|
(message "Acquiring Lisp for <briefcase>.%s" attr)
|
|
|
|
(make-process :name (format "nix-build/%s" attr)
|
2020-01-23 23:02:13 +01:00
|
|
|
:buffer outbuf
|
|
|
|
:stderr errbuf
|
|
|
|
:command command
|
|
|
|
:sentinel
|
|
|
|
(lambda (process event)
|
|
|
|
(unwind-protect
|
|
|
|
(pcase event
|
|
|
|
("finished\n"
|
2020-08-31 15:09:24 +02:00
|
|
|
(let* ((outpath (s-trim (with-current-buffer outbuf
|
|
|
|
(buffer-string))))
|
2020-01-23 23:02:13 +01:00
|
|
|
(lisp-path (s-concat outpath "/bin/sbcl")))
|
2020-08-31 15:09:24 +02:00
|
|
|
(message "Acquired Lisp for <briefcase>.%s at %s"
|
|
|
|
attr lisp-path)
|
2020-01-23 23:02:13 +01:00
|
|
|
(sly lisp-path)))
|
|
|
|
(_ (with-current-buffer errbuf
|
2020-08-31 15:09:24 +02:00
|
|
|
(error "Failed to build '%s':\n%s" attr
|
|
|
|
(buffer-string)))))
|
2020-01-23 23:02:13 +01:00
|
|
|
(kill-buffer outbuf)
|
|
|
|
(kill-buffer errbuf))))))
|
|
|
|
|
2018-09-04 21:00:18 +02:00
|
|
|
(provide 'wpc-nix)
|
|
|
|
;;; wpc-nix.el ends here
|