Skip to content

Commit

Permalink
emacs: stop vendoring PR NixOS#234651
Browse files Browse the repository at this point in the history
Previously, we vendor PR NixOS#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 NixOS#234651.

Considering that passing packageRequires to stdenv.mkDerivation also
works well, we stop filtering it out and stop vendoring PR NixOS#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
  • Loading branch information
jian-lin committed Aug 5, 2024
1 parent 37df73d commit 5248f6f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 72 deletions.
4 changes: 2 additions & 2 deletions pkgs/applications/editors/emacs/build-support/elpa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions pkgs/applications/editors/emacs/build-support/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -77,7 +76,7 @@ libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs:

// optionalAttrs (emacs.withNativeCompilation or false) {

addEmacsNativeLoadPath = true;
addEmacsNativeLoadPath = args.addEmacsNativeLoadPath or true;

inherit turnCompilationWarningToError ignoreCompilationError;

Expand All @@ -100,4 +99,4 @@ libBuildHelper.adaptMkDerivation { } stdenv.mkDerivation (finalAttrs:
'' + postInstall;
}

// removeAttrs args handledArgs)
)
57 changes: 3 additions & 54 deletions pkgs/applications/editors/emacs/build-support/lib-build-helper.nix
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions pkgs/applications/editors/emacs/build-support/melpa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/editors/emacs/build-support/trivial.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5248f6f

Please sign in to comment.