build-support/emacs: refactor

- Remove superflous `let` with `defaultMeta`

These can just be assigned to meta directly instead.

- Hoist internal intermediate derivation

- Remove top-level `with lib`

- Inherit `lib`/`builtins` into scopes
This commit is contained in:
adisbladis 2023-12-29 01:16:49 +13:00
parent 05d50dc97a
commit 3618d1d247
4 changed files with 70 additions and 73 deletions

View file

@ -2,7 +2,11 @@
{ lib, stdenv, emacs, texinfo, writeText, gcc }: { lib, stdenv, emacs, texinfo, writeText, gcc }:
with lib; let
handledArgs = [ "files" "fileSpecs" "meta" ];
genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; };
in
{ pname { pname
, version , version
@ -11,15 +15,7 @@ with lib;
, ... , ...
}@args: }@args:
let genericBuild ({
defaultMeta = {
homepage = args.src.meta.homepage or "https://elpa.gnu.org/packages/${pname}.html";
};
in
import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; } ({
dontUnpack = true; dontUnpack = true;
@ -33,9 +29,9 @@ import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; } ({
runHook postInstall runHook postInstall
''; '';
meta = defaultMeta // meta; meta = {
homepage = args.src.meta.homepage or "https://elpa.gnu.org/packages/${pname}.html";
} // meta;
} }
// removeAttrs args [ "files" "fileSpecs" // removeAttrs args handledArgs)
"meta"
])

View file

@ -2,6 +2,26 @@
{ lib, stdenv, emacs, texinfo, writeText, gcc, ... }: { 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 { pname
, version , version
, buildInputs ? [] , buildInputs ? []
@ -10,15 +30,6 @@
, ... , ...
}@args: }@args:
let
defaultMeta = {
broken = false;
platforms = emacs.meta.platforms;
} // lib.optionalAttrs ((args.src.meta.homepage or "") != "") {
homepage = args.src.meta.homepage;
};
in
stdenv.mkDerivation (finalAttrs: ({ stdenv.mkDerivation (finalAttrs: ({
name = "emacs-${pname}-${finalAttrs.version}"; name = "emacs-${pname}-${finalAttrs.version}";
@ -42,28 +53,21 @@ stdenv.mkDerivation (finalAttrs: ({
propagatedBuildInputs = packageRequires; propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires; propagatedUserEnvPkgs = packageRequires;
setupHook = writeText "setup-hook.sh" '' inherit setupHook;
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
'';
doCheck = false; doCheck = false;
meta = defaultMeta // meta; meta = {
broken = false;
platforms = emacs.meta.platforms;
} // optionalAttrs ((args.src.meta.homepage or "") != "") {
homepage = args.src.meta.homepage;
} // meta;
} }
// lib.optionalAttrs (emacs.withNativeCompilation or false) { // optionalAttrs (emacs.withNativeCompilation or false) {
LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib"; LIBRARY_PATH = "${getLib stdenv.cc.libc}/lib";
nativeBuildInputs = [ gcc ]; nativeBuildInputs = [ gcc ];
@ -83,4 +87,4 @@ stdenv.mkDerivation (finalAttrs: ({
''; '';
} }
// removeAttrs args [ "buildInputs" "packageRequires" "meta" ])) // removeAttrs args handledArgs))

View file

@ -3,37 +3,8 @@
{ lib, stdenv, fetchFromGitHub, emacs, texinfo, writeText, gcc }: { lib, stdenv, fetchFromGitHub, emacs, texinfo, writeText, gcc }:
with lib;
{ /*
pname: Nix package name without special symbols and without version or
"emacs-" prefix.
*/
pname
/*
ename: Original Emacs package name, possibly containing special symbols.
*/
, ename ? null
, version
, recipe
, meta ? {}
, ...
}@args:
let let
genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; };
defaultMeta = {
homepage = args.src.meta.homepage or "https://melpa.org/#/${pname}";
};
in
import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; } ({
ename =
if ename == null
then pname
else ename;
packageBuild = stdenv.mkDerivation { packageBuild = stdenv.mkDerivation {
name = "package-build"; name = "package-build";
@ -55,9 +26,35 @@ import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; } ({
"; ";
}; };
in
{ /*
pname: Nix package name without special symbols and without version or
"emacs-" prefix.
*/
pname
/*
ename: Original Emacs package name, possibly containing special symbols.
*/
, ename ? null
, version
, recipe
, meta ? {}
, ...
}@args:
genericBuild ({
ename =
if ename == null
then pname
else ename;
elpa2nix = ./elpa2nix.el; elpa2nix = ./elpa2nix.el;
melpa2nix = ./melpa2nix.el; melpa2nix = ./melpa2nix.el;
inherit packageBuild;
preUnpack = '' preUnpack = ''
mkdir -p "$NIX_BUILD_TOP/recipes" mkdir -p "$NIX_BUILD_TOP/recipes"
if [ -n "$recipe" ]; then if [ -n "$recipe" ]; then
@ -104,7 +101,9 @@ import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; } ({
runHook postInstall runHook postInstall
''; '';
meta = defaultMeta // meta; meta = {
homepage = args.src.meta.homepage or "https://melpa.org/#/${pname}";
} // meta;
} }
// removeAttrs args [ "meta" ]) // removeAttrs args [ "meta" ])

View file

@ -2,8 +2,6 @@
{ callPackage, lib, ... }@envargs: { callPackage, lib, ... }@envargs:
with lib;
args: args:
callPackage ./generic.nix envargs ({ callPackage ./generic.nix envargs ({