2018-09-04 21:00:18 +02:00
|
|
|
;;; wpc-nix.el --- Nix support -*- lexical-binding: t -*-
|
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
|
|
|
|
|
|
|
;;; 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-04-02 15:50:53 +02:00
|
|
|
(let* ((emacs (if (device/corporate?) "emacs.glinux" "emacs.nixos"))
|
|
|
|
(pname (format "nix-build <briefcase/%s>" emacs))
|
|
|
|
(bname (format "*%s*" pname)))
|
|
|
|
(start-process pname bname
|
|
|
|
"nix-env"
|
2020-08-25 15:19:19 +02:00
|
|
|
"-I" (format "briefcase=%s" constants/briefcase)
|
2020-04-02 15:50:53 +02:00
|
|
|
"-f" "<briefcase>" "-iA" emacs)
|
|
|
|
(display-buffer bname)))
|
2020-02-02 14:45:06 +01:00
|
|
|
|
2020-08-31 15:09:24 +02:00
|
|
|
(defun wpc-nix-home-manager-switch ()
|
2020-03-06 12:22:56 +01:00
|
|
|
"Use Nix to reconfigure the user environment."
|
|
|
|
(interactive)
|
2020-08-31 15:09:24 +02:00
|
|
|
(start-process "wpc-nix-home-manager-switch" "*wpc-nix-home-manager-switch*"
|
2020-03-06 12:22:56 +01:00
|
|
|
"home-manager"
|
2020-08-25 14:55:14 +02:00
|
|
|
"-I" (format "nixpkgs=%s" (f-expand "~/nixpkgs-channels"))
|
2020-03-06 12:22:56 +01:00
|
|
|
"-I" (format "home-manager=%s" (f-expand "~/home-manager"))
|
|
|
|
"switch")
|
2020-08-31 15:09:24 +02:00
|
|
|
(display-buffer "*wpc-nix-home-manager-switch*"))
|
2020-01-23 23:02:13 +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
|