-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
emacs: teach elisp builders the finalAttrs pattern #330589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b82c96
675dcef
cdf4aef
84c2e00
37df73d
5248f6f
5805cf2
e64ccec
bdd7734
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost all other attrs are overridden by user-defined values. Applying that pattern to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, well, well... Searching some packages, I have found that e.g. postInstallHooks+=(copyDesktopItems)
# rest of codeIt implies that post installation hooks are "queued" but not destroyed/substituted. That being said, curiously the consistency is not in substituting pre/post phases, but in queueing them.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that there are two kinds of postInstall hooks, one is defined in nix files with the attr
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another question, which one of the two orders should be used for |
||
| } | ||
|
|
||
| // removeAttrs args handledArgs)) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| extendMkDerivation' = | ||
| mkDerivationBase: attrsOverlay: fpargs: | ||
| (mkDerivationBase fpargs).overrideAttrs attrsOverlay; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,24 +64,26 @@ 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" '' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something to address here and now:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I created #334888 to track this potential improvement. |
||
| (${finalAttrs.ename} :fetcher git :url "" | ||
| ${lib.optionalString (finalAttrs.files != null) ":files ${finalAttrs.files}"}) | ||
jian-lin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| '') | ||
| , preUnpack ? "" | ||
| , postUnpack ? "" | ||
| , meta ? {} | ||
| , ... | ||
| }@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 <version>-unstable-YYYY-MM-DD format | ||
|
|
@@ -90,7 +94,7 @@ genericBuild ({ | |
| in | ||
| if unstableVersionInNixFormat | ||
| then date + "." + time | ||
| else version; | ||
| else finalAttrs.version); | ||
|
|
||
| preUnpack = '' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost all other attrs are overridden by user-defined values. Should we apply that pattern to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Think in something like "oh the unpacker does not like dashes in the filename, let's change it to underscores first!" The So I would follow the same as I said to postInstall: |
||
| 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) | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.