nixpkgs/pkgs/build-support/emacs/elpa2nix.el
Thomas Tuegel decb5802c9 elpaBuild: factor out package installation
Building packages requires package-build.el from Melpa, but installing
packages only requires package.el. Packages from ELPA are already built,
so there is no need to involve package-build.el.
2016-01-18 15:29:19 -06:00

28 lines
911 B
EmacsLisp

(require 'package)
(package-initialize)
(defun elpa2nix-install-package ()
(if (not noninteractive)
(error "`elpa2nix-install-package' is to be used only with -batch"))
(pcase command-line-args-left
(`(,archive ,elpa)
(progn (setq package-user-dir elpa)
(elpa2nix-install-file archive)))))
(defun elpa2nix-install-from-buffer ()
"Install a package from the current buffer."
(let ((pkg-desc (if (derived-mode-p 'tar-mode)
(package-tar-file-info)
(package-buffer-info))))
;; Install the package itself.
(package-unpack pkg-desc)
pkg-desc))
(defun elpa2nix-install-file (file)
"Install a package from a file.
The file can either be a tar file or an Emacs Lisp file."
(with-temp-buffer
(insert-file-contents-literally file)
(when (string-match "\\.tar\\'" file) (tar-mode))
(elpa2nix-install-from-buffer)))