From decb5802c91915814fc6551442cd3f586a78de30 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sat, 16 Jan 2016 17:20:06 -0600 Subject: [PATCH] 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. --- .../editors/emacs-modes/elpa-packages.nix | 2 +- pkgs/build-support/emacs/elpa.nix | 30 +++++++++++++++++++ pkgs/build-support/emacs/elpa2nix.el | 27 +++++++++++++++++ pkgs/build-support/emacs/melpa.nix | 4 +-- pkgs/build-support/emacs/melpa2nix.el | 25 ---------------- 5 files changed, 60 insertions(+), 28 deletions(-) create mode 100644 pkgs/build-support/emacs/elpa.nix create mode 100644 pkgs/build-support/emacs/elpa2nix.el diff --git a/pkgs/applications/editors/emacs-modes/elpa-packages.nix b/pkgs/applications/editors/emacs-modes/elpa-packages.nix index 60cd4251888..7fc8a06644f 100644 --- a/pkgs/applications/editors/emacs-modes/elpa-packages.nix +++ b/pkgs/applications/editors/emacs-modes/elpa-packages.nix @@ -23,7 +23,7 @@ self: super = removeAttrs imported [ "dash" ]; - elpaBuild = import ../../../build-support/emacs/melpa.nix { + elpaBuild = import ../../../build-support/emacs/elpa.nix { inherit fetchurl lib stdenv texinfo; inherit (self) emacs; }; diff --git a/pkgs/build-support/emacs/elpa.nix b/pkgs/build-support/emacs/elpa.nix new file mode 100644 index 00000000000..79a26abcb83 --- /dev/null +++ b/pkgs/build-support/emacs/elpa.nix @@ -0,0 +1,30 @@ +# builder for Emacs packages built for packages.el + +{ lib, stdenv, fetchurl, emacs, texinfo }: + +with lib; + +{ pname +, version +, src +, ... +}@args: + +import ./generic.nix { inherit lib stdenv emacs texinfo; } ({ + + phases = "installPhase fixupPhase distPhase"; + + installPhase = '' + runHook preInstall + + emacs --batch -Q -l ${./elpa2nix.el} \ + -f elpa2nix-install-package \ + "${src}" "$out/share/emacs/site-lisp/elpa" + + runHook postInstall + ''; +} + +// removeAttrs args [ "files" "fileSpecs" + "meta" + ]) diff --git a/pkgs/build-support/emacs/elpa2nix.el b/pkgs/build-support/emacs/elpa2nix.el new file mode 100644 index 00000000000..3a2d65d640f --- /dev/null +++ b/pkgs/build-support/emacs/elpa2nix.el @@ -0,0 +1,27 @@ +(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))) diff --git a/pkgs/build-support/emacs/melpa.nix b/pkgs/build-support/emacs/melpa.nix index fb244081147..3b8a23d8c2a 100644 --- a/pkgs/build-support/emacs/melpa.nix +++ b/pkgs/build-support/emacs/melpa.nix @@ -63,8 +63,8 @@ import ./generic.nix { inherit lib stdenv emacs texinfo; } ({ installPhase = '' runHook preInstall - emacs --batch -Q -l $packageBuild -l ${./melpa2nix.el} \ - -f melpa2nix-install-package \ + emacs --batch -Q -l ${./elpa2nix.el} \ + -f elpa2nix-install-package \ "$archive" "$out/share/emacs/site-lisp/elpa" runHook postInstall diff --git a/pkgs/build-support/emacs/melpa2nix.el b/pkgs/build-support/emacs/melpa2nix.el index fb35fc68125..3cd5bbdb954 100644 --- a/pkgs/build-support/emacs/melpa2nix.el +++ b/pkgs/build-support/emacs/melpa2nix.el @@ -6,14 +6,6 @@ (setq package-build-working-dir (expand-file-name ".") package-build-archive-dir (expand-file-name ".")) -(defun melpa2nix-install-package () - (if (not noninteractive) - (error "`melpa2nix-install-package' is to be used only with -batch")) - (pcase command-line-args-left - (`(,archive ,elpa) - (progn (setq package-user-dir elpa) - (melpa2nix-install-file archive))))) - (defun melpa2nix-build-package () (if (not noninteractive) (error "`melpa2nix-build-package' is to be used only with -batch")) @@ -48,20 +40,3 @@ (time-to-seconds (time-since start-time)) (current-time-string)) (princ (format "%s\n" archive-file))))) - -(defun melpa2nix-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 melpa2nix-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)) - (melpa2nix-install-from-buffer)))