nixpkgs/pkgs/applications/editors/emacs/build-support/generic.nix
Anderson Torres 368f163caa emacs: migrate build-support/emacs to applications/editors/emacs/build-support
As a consequence of restrictions imposed by RFC 140 - Simple Package Paths [1]
-, files related to a package should be confined on the package directory.

Certainly this restriction does not apply to packages outside by-name hierarchy.

Nonetheless, this is an interesting organization heuristics: things that affect
Emacs should be confined inside Emacs directory. Besides a future migration, the
"debuggability" of a framework is way more enhanced when we know how to find all
its files.

A similar task was done before, when RFC 140 was not a thging yet - namely, the
migration of emacs-modes to elisp-packages [2].

[1] https://github.com/NixOS/rfcs/pull/140
[2] https://github.com/NixOS/nixpkgs/pull/123859
2024-07-06 09:41:13 -03:00

91 lines
2.3 KiB
Nix

# 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}";
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
'';
buildInputs = [emacs texinfo] ++ packageRequires ++ buildInputs;
propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires;
inherit setupHook;
doCheck = false;
meta = {
broken = false;
platforms = emacs.meta.platforms;
} // optionalAttrs ((args.src.meta.homepage or "") != "") {
homepage = args.src.meta.homepage;
} // meta;
}
// optionalAttrs (emacs.withNativeCompilation or false) {
LIBRARY_PATH = "${getLib stdenv.cc.libc}/lib";
nativeBuildInputs = [ gcc ];
addEmacsNativeLoadPath = true;
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"
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"
'';
}
// removeAttrs args handledArgs))