diff --git a/pkgs/applications/editors/emacs/build-support/elpa.nix b/pkgs/applications/editors/emacs/build-support/elpa.nix index 7ac8d673346ae..5a8f0ab9e52c8 100644 --- a/pkgs/applications/editors/emacs/build-support/elpa.nix +++ b/pkgs/applications/editors/emacs/build-support/elpa.nix @@ -3,26 +3,29 @@ { lib, stdenv, emacs, texinfo, writeText }: let - handledArgs = [ "meta" ]; genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText; }; + libBuildHelper = import ./lib-build-helper.nix; in +libBuildHelper.extendMkDerivation' genericBuild (finalAttrs: + { pname -, version -, src +, dontUnpack ? true , meta ? {} , ... }@args: -genericBuild ({ +{ + + elpa2nix = args.elpa2nix or ./elpa2nix.el; - dontUnpack = true; + inherit dontUnpack; - installPhase = '' + installPhase = args.installPhase or '' runHook preInstall - emacs --batch -Q -l ${./elpa2nix.el} \ + emacs --batch -Q -l "$elpa2nix" \ -f elpa2nix-install-package \ "$src" "$out/share/emacs/site-lisp/elpa" @@ -34,4 +37,4 @@ genericBuild ({ } // meta; } -// removeAttrs args handledArgs) +) diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index 3b3298cd14685..3ff10ee865fb3 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -4,8 +4,6 @@ let inherit (lib) optionalAttrs; - handledArgs = [ "buildInputs" "nativeBuildInputs" "packageRequires" "propagatedUserEnvPkgs" "meta" ] - ++ lib.optionals (emacs.withNativeCompilation or false) [ "postInstall" ]; setupHook = writeText "setup-hook.sh" '' source ${./emacs-funcs.sh} @@ -21,13 +19,16 @@ let fi ''; + libBuildHelper = import ./lib-build-helper.nix; + in -{ pname -, version -, buildInputs ? [] +libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs: + +{ buildInputs ? [] , nativeBuildInputs ? [] , packageRequires ? [] +, propagatedBuildInputs ? [] , propagatedUserEnvPkgs ? [] , postInstall ? "" , meta ? {} @@ -36,10 +37,10 @@ in , ... }@args: -stdenv.mkDerivation (finalAttrs: ({ - name = "emacs-${pname}-${finalAttrs.version}"; +{ + name = args.name or "emacs-${finalAttrs.pname}-${finalAttrs.version}"; - unpackCmd = '' + unpackCmd = args.unpackCmd or '' case "$curSrc" in *.el) # keep original source filename without the hash @@ -55,14 +56,13 @@ stdenv.mkDerivation (finalAttrs: ({ esac ''; - buildInputs = packageRequires ++ buildInputs; + inherit packageRequires; + buildInputs = finalAttrs.packageRequires ++ buildInputs; nativeBuildInputs = [ emacs texinfo ] ++ nativeBuildInputs; - propagatedBuildInputs = packageRequires; - propagatedUserEnvPkgs = packageRequires ++ propagatedUserEnvPkgs; - - inherit setupHook; + propagatedBuildInputs = finalAttrs.packageRequires ++ propagatedBuildInputs; + propagatedUserEnvPkgs = finalAttrs.packageRequires ++ propagatedUserEnvPkgs; - doCheck = false; + setupHook = args.setupHook or setupHook; meta = { broken = false; @@ -74,7 +74,7 @@ stdenv.mkDerivation (finalAttrs: ({ // optionalAttrs (emacs.withNativeCompilation or false) { - addEmacsNativeLoadPath = true; + addEmacsNativeLoadPath = args.addEmacsNativeLoadPath or true; inherit turnCompilationWarningToError ignoreCompilationError; @@ -97,4 +97,4 @@ stdenv.mkDerivation (finalAttrs: ({ '' + postInstall; } -// removeAttrs args handledArgs)) +) diff --git a/pkgs/applications/editors/emacs/build-support/lib-build-helper.nix b/pkgs/applications/editors/emacs/build-support/lib-build-helper.nix new file mode 100644 index 0000000000000..23267f592359e --- /dev/null +++ b/pkgs/applications/editors/emacs/build-support/lib-build-helper.nix @@ -0,0 +1,5 @@ +{ + extendMkDerivation' = + mkDerivationBase: attrsOverlay: fpargs: + (mkDerivationBase fpargs).overrideAttrs attrsOverlay; +} diff --git a/pkgs/applications/editors/emacs/build-support/melpa.nix b/pkgs/applications/editors/emacs/build-support/melpa.nix index 20f7e79eb683d..718a0c4d2c1c0 100644 --- a/pkgs/applications/editors/emacs/build-support/melpa.nix +++ b/pkgs/applications/editors/emacs/build-support/melpa.nix @@ -4,8 +4,8 @@ { lib, stdenv, fetchFromGitHub, emacs, texinfo, writeText }: let - handledArgs = [ "meta" "preUnpack" "postUnpack" ]; genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText; }; + libBuildHelper = import ./lib-build-helper.nix; packageBuild = stdenv.mkDerivation { name = "package-build"; @@ -29,6 +29,8 @@ let in +libBuildHelper.extendMkDerivation' genericBuild (finalAttrs: + { /* pname: Nix package name without special symbols and without version or "emacs-" prefix. @@ -51,7 +53,7 @@ in This will be written into the generated package but it is not needed during the build process. */ -, commit ? (args.src.rev or "unknown") +, commit ? (finalAttrs.src.rev or "unknown") /* files: Optional recipe property specifying the files used to build the package. If null, do not set it in recipe, keeping the default upstream behaviour. @@ -62,9 +64,9 @@ in recipe: Optional MELPA recipe. Default: a minimally functional recipe */ -, recipe ? (writeText "${pname}-recipe" '' - (${ename} :fetcher git :url "" - ${lib.optionalString (files != null) ":files ${files}"}) +, recipe ? (writeText "${finalAttrs.pname}-recipe" '' + (${finalAttrs.ename} :fetcher git :url "" + ${lib.optionalString (finalAttrs.files != null) ":files ${finalAttrs.files}"}) '') , preUnpack ? "" , postUnpack ? "" @@ -72,14 +74,16 @@ in , ... }@args: -genericBuild ({ +{ + + elpa2nix = args.elpa2nix or ./elpa2nix.el; + melpa2nix = args.melpa2nix or ./melpa2nix.el; - elpa2nix = ./elpa2nix.el; - melpa2nix = ./melpa2nix.el; + inherit commit ename files recipe; - inherit packageBuild commit ename recipe; + packageBuild = args.packageBuild or packageBuild; - melpaVersion = + melpaVersion = args.melpaVersion or ( let parsed = lib.flip builtins.match version # match -unstable-YYYY-MM-DD format @@ -90,7 +94,7 @@ genericBuild ({ in if unstableVersionInNixFormat then date + "." + time - else version; + else finalAttrs.version); preUnpack = '' mkdir -p "$NIX_BUILD_TOP/recipes" @@ -108,7 +112,7 @@ genericBuild ({ ln -s "$NIX_BUILD_TOP/$sourceRoot" "$NIX_BUILD_TOP/working/$ename" '' + postUnpack; - buildPhase = '' + buildPhase = args.buildPhase or '' runHook preBuild cd "$NIX_BUILD_TOP" @@ -122,7 +126,7 @@ genericBuild ({ runHook postBuild ''; - installPhase = '' + installPhase = args.installPhase or '' runHook preInstall archive="$NIX_BUILD_TOP/packages/$ename-$melpaVersion.el" @@ -143,4 +147,4 @@ genericBuild ({ } // meta; } -// removeAttrs args handledArgs) +) diff --git a/pkgs/applications/editors/emacs/build-support/trivial.nix b/pkgs/applications/editors/emacs/build-support/trivial.nix index 11c28c0133e40..2c20b0567c68d 100644 --- a/pkgs/applications/editors/emacs/build-support/trivial.nix +++ b/pkgs/applications/editors/emacs/build-support/trivial.nix @@ -2,10 +2,16 @@ { callPackage, lib, ... }@envargs: +let + libBuildHelper = import ./lib-build-helper.nix; +in + +libBuildHelper.extendMkDerivation' (callPackage ./generic.nix envargs) (finalAttrs: + args: -callPackage ./generic.nix envargs ({ - buildPhase = '' +{ + buildPhase = args.buildPhase or '' runHook preBuild emacs -L . --batch -f batch-byte-compile *.el @@ -13,16 +19,15 @@ callPackage ./generic.nix envargs ({ runHook postBuild ''; - installPhase = '' + installPhase = args.installPhase or '' runHook preInstall LISPDIR=$out/share/emacs/site-lisp install -d $LISPDIR install *.el *.elc $LISPDIR - emacs --batch -l package --eval "(package-generate-autoloads \"${args.pname}\" \"$LISPDIR\")" runHook postInstall ''; } -// args) +)