2014-01-21 00:57:04 +01:00
|
|
|
# generic builder for Emacs packages
|
|
|
|
|
2021-06-12 18:21:35 +02:00
|
|
|
{ lib, stdenv, emacs, texinfo, writeText, gcc, ... }:
|
2014-01-21 00:57:04 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{ pname
|
|
|
|
, version ? null
|
|
|
|
|
|
|
|
, buildInputs ? []
|
|
|
|
, packageRequires ? []
|
|
|
|
|
|
|
|
, meta ? {}
|
|
|
|
|
|
|
|
, ...
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
2015-05-24 16:06:12 +02:00
|
|
|
|
2014-01-21 00:57:04 +01:00
|
|
|
defaultMeta = {
|
|
|
|
broken = false;
|
|
|
|
platforms = emacs.meta.platforms;
|
2015-05-24 16:06:12 +02:00
|
|
|
} // optionalAttrs ((args.src.meta.homepage or "") != "") {
|
|
|
|
homepage = args.src.meta.homepage;
|
2014-01-21 00:57:04 +01:00
|
|
|
};
|
2015-05-24 16:06:12 +02:00
|
|
|
|
2014-01-21 00:57:04 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation ({
|
|
|
|
name = "emacs-${pname}${optionalString (version != null) "-${version}"}";
|
|
|
|
|
2015-04-16 17:09:28 +02:00
|
|
|
unpackCmd = ''
|
|
|
|
case "$curSrc" in
|
|
|
|
*.el)
|
2016-01-16 23:47:22 +01:00
|
|
|
# keep original source filename without the hash
|
|
|
|
local filename=$(basename "$curSrc")
|
|
|
|
filename="''${filename:33}"
|
|
|
|
cp $curSrc $filename
|
|
|
|
chmod +w $filename
|
2015-04-16 17:09:28 +02:00
|
|
|
sourceRoot="."
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
_defaultUnpack "$curSrc"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
|
2014-01-21 00:57:04 +01:00
|
|
|
buildInputs = [emacs texinfo] ++ packageRequires ++ buildInputs;
|
|
|
|
propagatedBuildInputs = packageRequires;
|
|
|
|
propagatedUserEnvPkgs = packageRequires;
|
|
|
|
|
2020-12-28 05:12:44 +01:00
|
|
|
setupHook = writeText "setup-hook.sh" ''
|
|
|
|
source ${./emacs-funcs.sh}
|
|
|
|
|
|
|
|
if [[ ! -v emacsHookDone ]]; then
|
|
|
|
emacsHookDone=1
|
|
|
|
|
|
|
|
# If this is for a wrapper derivation, emacs and the dependencies are all
|
|
|
|
# run-time dependencies. If this is for precompiling packages into bytecode,
|
|
|
|
# emacs is a compile-time dependency of the package.
|
|
|
|
addEnvHooks "$hostOffset" addEmacsVars
|
|
|
|
addEnvHooks "$targetOffset" addEmacsVars
|
|
|
|
fi
|
|
|
|
'';
|
2014-01-21 00:57:04 +01:00
|
|
|
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
meta = defaultMeta // meta;
|
|
|
|
}
|
|
|
|
|
2020-07-23 21:34:55 +02:00
|
|
|
// lib.optionalAttrs (emacs.nativeComp or false) {
|
|
|
|
|
|
|
|
LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
|
|
|
|
|
2021-06-12 18:21:35 +02:00
|
|
|
nativeBuildInputs = [ gcc ];
|
|
|
|
|
2020-11-16 20:24:29 +01:00
|
|
|
addEmacsNativeLoadPath = true;
|
|
|
|
|
2020-07-23 21:34:55 +02:00
|
|
|
postInstall = ''
|
2020-12-28 05:12:44 +01:00
|
|
|
# Besides adding the output directory to the native load path, make sure
|
|
|
|
# the current package's elisp files are in the load path, otherwise
|
|
|
|
# (require 'file-b) from file-a.el in the same package will fail.
|
|
|
|
mkdir -p $out/share/emacs/native-lisp
|
|
|
|
source ${./emacs-funcs.sh}
|
|
|
|
addEmacsVars "$out"
|
|
|
|
|
2020-11-16 20:24:29 +01:00
|
|
|
find $out/share/emacs -type f -name '*.el' -print0 \
|
|
|
|
| xargs -0 -n 1 -I {} -P $NIX_BUILD_CORES sh -c \
|
2020-12-28 05:12:44 +01:00
|
|
|
"emacs --batch -f batch-native-compile {} || true"
|
2020-07-23 21:34:55 +02:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
|
2014-01-21 00:57:04 +01:00
|
|
|
// removeAttrs args [ "buildInputs" "packageRequires"
|
|
|
|
"meta"
|
|
|
|
])
|