From 5248f6f8ef5bae4f848adf9865ee1cd792707f0e Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sun, 4 Aug 2024 08:56:14 +0800 Subject: [PATCH] emacs: stop vendoring PR #234651 Previously, we vendor PR #234651 because we want to keep the old behavior of filtering out packageRequires from the arguments we pass to the underling stdenv.mkDerivation. Doing so raises the concern about the complexity of PR #234651. Considering that passing packageRequires to stdenv.mkDerivation also works well, we stop filtering it out and stop vendoring PR #234651. Now, this PR only uses the existing interface of stdenv.mkDerivation. Even though the name of the build helper is still extendMkDerivation', it is nothing new and has been used in Nixpkgs, such as php.buildComposerProject[1]. [1]: https://github.com/NixOS/nixpkgs/blob/f3834de3782b82bfc666abf664f946d0e7d1f116/pkgs/build-support/php/builders/v1/build-composer-project.nix#L108 --- .../editors/emacs/build-support/elpa.nix | 4 +- .../editors/emacs/build-support/generic.nix | 23 ++++---- .../emacs/build-support/lib-build-helper.nix | 57 +------------------ .../editors/emacs/build-support/melpa.nix | 4 +- .../editors/emacs/build-support/trivial.nix | 4 +- 5 files changed, 20 insertions(+), 72 deletions(-) diff --git a/pkgs/applications/editors/emacs/build-support/elpa.nix b/pkgs/applications/editors/emacs/build-support/elpa.nix index c87457ff16d93..3e40cd6df56b7 100644 --- a/pkgs/applications/editors/emacs/build-support/elpa.nix +++ b/pkgs/applications/editors/emacs/build-support/elpa.nix @@ -4,11 +4,11 @@ let genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText; }; - libBuildHelper = import ./lib-build-helper.nix { inherit lib; }; + libBuildHelper = import ./lib-build-helper.nix; in -libBuildHelper.extendMkDerivation { } genericBuild (finalAttrs: +libBuildHelper.extendMkDerivation' genericBuild (finalAttrs: { pname , version diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index 914387979fc2d..a3943dda188cd 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" "propagatedBuildInputs" "propagatedUserEnvPkgs" "meta" ] - ++ lib.optionals (emacs.withNativeCompilation or false) [ "postInstall" ]; setupHook = writeText "setup-hook.sh" '' source ${./emacs-funcs.sh} @@ -21,11 +19,11 @@ let fi ''; - libBuildHelper = import ./lib-build-helper.nix { inherit lib; }; + libBuildHelper = import ./lib-build-helper.nix; in -libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs: +libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs: { pname , version @@ -42,9 +40,9 @@ libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs: }@args: { - name = "emacs-${finalAttrs.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 @@ -60,12 +58,13 @@ libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs: esac ''; - buildInputs = packageRequires ++ buildInputs; + inherit packageRequires; + buildInputs = finalAttrs.packageRequires ++ buildInputs; nativeBuildInputs = [ emacs texinfo ] ++ nativeBuildInputs; - propagatedBuildInputs = packageRequires ++ propagatedBuildInputs; - propagatedUserEnvPkgs = packageRequires ++ propagatedUserEnvPkgs; + propagatedBuildInputs = finalAttrs.packageRequires ++ propagatedBuildInputs; + propagatedUserEnvPkgs = finalAttrs.packageRequires ++ propagatedUserEnvPkgs; - inherit setupHook; + setupHook = args.setupHook or setupHook; meta = { broken = false; @@ -77,7 +76,7 @@ libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs: // optionalAttrs (emacs.withNativeCompilation or false) { - addEmacsNativeLoadPath = true; + addEmacsNativeLoadPath = args.addEmacsNativeLoadPath or true; inherit turnCompilationWarningToError ignoreCompilationError; @@ -100,4 +99,4 @@ libBuildHelper.adaptMkDerivation { } 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 index 7ae7003c93528..23267f592359e 100644 --- a/pkgs/applications/editors/emacs/build-support/lib-build-helper.nix +++ b/pkgs/applications/editors/emacs/build-support/lib-build-helper.nix @@ -1,56 +1,5 @@ -# stolen from https://github.com/NixOS/nixpkgs/pull/234651 -# TODO switch to functions in that PR once it is merged - -{ lib }: - -let - inherit (lib) - setFunctionArgs - id - functionArgs - optionalAttrs - toFunction - ; -in { - - extendMkDerivation = - { - modify ? id, - inheritFunctionArgs ? true, - }: - mkDerivationBase: attrsOverlay: - setFunctionArgs - # Adds the fixed-point style support. - (fpargs: modify ((mkDerivationBase fpargs).overrideAttrs attrsOverlay)) - # Add __functionArgs - ( - # Inherit the __functionArgs from the base build helper - functionArgs (attrsOverlay { }) - # Recover the __functionArgs from the derived build helper - // optionalAttrs inheritFunctionArgs (functionArgs mkDerivationBase) - ) - // { - # Passthru attributes attached to the result build helper. - attrsOverlays = mkDerivationBase.attrsOverlays or [ ] ++ [ attrsOverlay ]; - }; - - adaptMkDerivation = - { - modify ? id, - inheritFunctionArgs ? true, - }: - mkDerivationBase: adaptArgs: - setFunctionArgs - # Adds the fixed-point style support - ( - fpargs: modify (mkDerivationBase (finalAttrs: adaptArgs finalAttrs (toFunction fpargs finalAttrs))) - ) - # Add __functionArgs - ( - # Inherit the __functionArgs from the base build helper - optionalAttrs inheritFunctionArgs (functionArgs mkDerivationBase) - # Recover the __functionArgs from the derived build helper - // functionArgs (adaptArgs { }) - ); + 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 c5adaac765485..4a22ea195a985 100644 --- a/pkgs/applications/editors/emacs/build-support/melpa.nix +++ b/pkgs/applications/editors/emacs/build-support/melpa.nix @@ -5,7 +5,7 @@ let genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText; }; - libBuildHelper = import ./lib-build-helper.nix { inherit lib; }; + libBuildHelper = import ./lib-build-helper.nix; packageBuild = stdenv.mkDerivation { name = "package-build"; @@ -29,7 +29,7 @@ let in -libBuildHelper.extendMkDerivation { } genericBuild (finalAttrs: +libBuildHelper.extendMkDerivation' genericBuild (finalAttrs: { /* pname: Nix package name without special symbols and without version or diff --git a/pkgs/applications/editors/emacs/build-support/trivial.nix b/pkgs/applications/editors/emacs/build-support/trivial.nix index 71606d463a829..fa3cd2fe56332 100644 --- a/pkgs/applications/editors/emacs/build-support/trivial.nix +++ b/pkgs/applications/editors/emacs/build-support/trivial.nix @@ -3,10 +3,10 @@ { callPackage, lib, ... }@envargs: let - libBuildHelper = import ./lib-build-helper.nix { inherit lib; }; + libBuildHelper = import ./lib-build-helper.nix; in -libBuildHelper.extendMkDerivation { } (callPackage ./generic.nix envargs) (finalAttrs: +libBuildHelper.extendMkDerivation' (callPackage ./generic.nix envargs) (finalAttrs: { pname , version