core/pkgs/build-support/emacs/generic.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.6 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
# generic builder for Emacs packages
{
lib,
stdenv,
emacs,
texinfo,
writeText,
gcc,
...
}:
let
inherit (lib) optionalAttrs getLib;
handledArgs = [
"buildInputs"
"packageRequires"
"meta"
];
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
'';
in
{
pname,
version,
buildInputs ? [ ],
packageRequires ? [ ],
meta ? { },
...
}@args:
stdenv.mkDerivation (
finalAttrs:
(
{
name = "emacs-${pname}-${finalAttrs.version}";
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
unpackCmd = ''
case "$curSrc" in
*.el)
# keep original source filename without the hash
local filename=$(basename "$curSrc")
filename="''${filename:33}"
cp $curSrc $filename
chmod +w $filename
sourceRoot="."
;;
*)
_defaultUnpack "$curSrc"
;;
esac
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
buildInputs = [
emacs
texinfo
] ++ packageRequires ++ buildInputs;
propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
inherit setupHook;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
doCheck = false;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
meta =
{
broken = false;
platforms = emacs.meta.platforms;
2024-06-30 08:16:52 +00:00
}
2024-05-02 00:46:19 +00:00
// optionalAttrs ((args.src.meta.homepage or "") != "") { homepage = args.src.meta.homepage; }
// meta;
}
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
// optionalAttrs (emacs.withNativeCompilation or false) {
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
LIBRARY_PATH = "${getLib stdenv.cc.libc}/lib";
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
nativeBuildInputs = [ gcc ];
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
addEmacsNativeLoadPath = true;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
postInstall = ''
# 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"
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
find $out/share/emacs -type f -name '*.el' -print0 \
| xargs -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \
"emacs --batch --eval '(setq large-file-warning-threshold nil)' -f batch-native-compile {} || true"
'';
}
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
// removeAttrs args handledArgs
2024-06-30 08:16:52 +00:00
)
2024-05-02 00:46:19 +00:00
)