main
 1{
 2  stdenv,
 3  lib,
 4  emacs,
 5  name,
 6  src,
 7  buildInputs ? [ ],
 8  patches ? [ ],
 9  preBuild ? "",
10}:
11
12stdenv.mkDerivation {
13  inherit name src patches;
14  unpackCmd = ''
15    test -f "${src}" && mkdir el && cp -p ${src} el/${name}
16  '';
17  buildInputs = [ emacs ] ++ buildInputs;
18  buildPhase = ''
19    runHook preBuild
20
21    ${preBuild}
22    ARGS=$(find ${lib.concatStrings (builtins.map (arg: arg + "/share/emacs/site-lisp ") buildInputs)} \
23                 -type d -exec echo -L {} \;)
24    mkdir $out
25    export HOME=$out
26    ${emacs}/bin/emacs -Q -nw -L . $ARGS --batch -f batch-byte-compile *.el
27
28    runHook postBuild
29  '';
30  installPhase = ''
31    runHook preInstall
32
33    mkdir -p $out/share/emacs/site-lisp
34    install *.el* $out/share/emacs/site-lisp
35
36    runHook postInstall
37  '';
38  meta = {
39    description = "Emacs projects from the Internet that just compile .el files";
40    homepage = "http://www.emacswiki.org";
41    license = lib.licenses.gpl3Plus; # Emacs packages are typically GPL
42    platforms = lib.platforms.all;
43  };
44}