summary refs log tree commit diff
path: root/pkgs/build-support/emacs/melpa2nix.el
blob: 72667dea652c15aed6cb63fea9294aa857a77f10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(require 'package)
(package-initialize)

(require 'package-recipe)
(require 'package-build)

(setq package-build-working-dir (expand-file-name "working/"))
(setq package-build-archive-dir (expand-file-name "packages/"))
(setq package-build-recipes-dir (expand-file-name "recipes/"))

;; Allow installing package tarfiles larger than 10MB
(setq large-file-warning-threshold nil)

(defun melpa2nix-build-package-1 (rcp version commit)
  (let ((source-dir (package-recipe--working-tree rcp)))
    (unwind-protect
        (let ((files (package-build-expand-files-spec rcp t)))
          (cond
           ((= (length files) 1)
            (package-build--build-single-file-package
             rcp version commit files source-dir))
           ((> (length files) 1)
            (package-build--build-multi-file-package
             rcp version commit files source-dir))
           (t (error "Unable to find files matching recipe patterns")))))))

(defun melpa2nix-build-package ()
  (if (not noninteractive)
      (error "`melpa2nix-build-package' is to be used only with -batch"))
  (pcase command-line-args-left
    (`(,package ,version ,commit)
     (melpa2nix-build-package-1 (package-recipe-lookup package) version commit))))