diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-12-09 15:53:10 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-01-06 12:12:53 +0000 |
commit | beaedc33b414d3be42006801c30ce5ccfc1c55af (patch) | |
tree | a48abc828d0775cf1e590250abd1eafb1acc0e6c /nixpkgs | |
parent | 9270b74fb4c6d4a21b86e5492dc43d78d8e05a03 (diff) | |
download | nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar.gz nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar.bz2 nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar.lz nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar.xz nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.tar.zst nixlib-beaedc33b414d3be42006801c30ce5ccfc1c55af.zip |
emacsWithPackages: mutate EMACSLOADPATH correctly
An empty entry in EMACSLOADPATH gets filled with the default value. This is presumably why the wrapper inserted a colon after the entry it added for the dependencies. But this naive approach wasn't always correct. For example, if the user ran emacs with EMACSLOADPATH=foo, the wrapper would insert the default value (by adding the trailing `:') even though the user was trying to expressly opt out of it. To do this correctly, here I've replaced makeWrapper with a bespoke script that will actually parse the EMACSLOADPATH provided in the environment (if given), and insert the wrapper's load path just before the default value. If EMACSLOADPATH is given but contains no default value, we respect that and don't add the wrapped dependencies at all. If no EMACSLOADPATH is given, we insert the wrapped dependencies before the default value, just like before. In this way, the wrapped Emacs should now behave as if the wrapped dependencies were part of Emacs's default load-path value.
Diffstat (limited to 'nixpkgs')
-rw-r--r-- | nixpkgs/pkgs/build-support/emacs/wrapper.nix | 16 | ||||
-rw-r--r-- | nixpkgs/pkgs/build-support/emacs/wrapper.sh | 26 |
2 files changed, 38 insertions, 4 deletions
diff --git a/nixpkgs/pkgs/build-support/emacs/wrapper.nix b/nixpkgs/pkgs/build-support/emacs/wrapper.nix index 1f2fbd8068e7..a3ab30afc632 100644 --- a/nixpkgs/pkgs/build-support/emacs/wrapper.nix +++ b/nixpkgs/pkgs/build-support/emacs/wrapper.nix @@ -155,8 +155,12 @@ runCommand for prog in $emacs/bin/*; do # */ local progname=$(basename "$prog") rm -f "$out/bin/$progname" - makeWrapper "$prog" "$out/bin/$progname" \ - --suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:" + + substitute ${./wrapper.sh} $out/bin/$progname \ + --subst-var-by bash ${emacs.stdenv.shell} \ + --subst-var-by wrapperSiteLisp "$deps/share/emacs/site-lisp" \ + --subst-var prog + chmod +x $out/bin/$progname done # Wrap MacOS app @@ -168,8 +172,12 @@ runCommand $emacs/Applications/Emacs.app/Contents/PkgInfo \ $emacs/Applications/Emacs.app/Contents/Resources \ $out/Applications/Emacs.app/Contents - makeWrapper $emacs/Applications/Emacs.app/Contents/MacOS/Emacs $out/Applications/Emacs.app/Contents/MacOS/Emacs \ - --suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:" + + substitute ${./wrapper.sh} $out/Applications/Emacs.app/Contents/MacOS/Emacs \ + --subst-var-by bash ${emacs.stdenv.shell} \ + --subst-var-by wrapperSiteLisp "$emacs/Applications/Emacs.app/Contents/MacOS/Emacs" \ + --subst-var prog + chmod +x $out/bin/$progname fi mkdir -p $out/share diff --git a/nixpkgs/pkgs/build-support/emacs/wrapper.sh b/nixpkgs/pkgs/build-support/emacs/wrapper.sh new file mode 100644 index 000000000000..3c011b7f1364 --- /dev/null +++ b/nixpkgs/pkgs/build-support/emacs/wrapper.sh @@ -0,0 +1,26 @@ +#!@bash@ + +IFS=: + +newLoadPath=() +added= + +if [[ -n $EMACSLOADPATH ]] +then + while read -rd: entry + do + if [[ -z $entry && -z $added ]] + then + newLoadPath+=(@wrapperSiteLisp@) + added=1 + fi + newLoadPath+=("$entry") + done <<< "$EMACSLOADPATH:" +else + newLoadPath+=(@wrapperSiteLisp@) + newLoadPath+=("") +fi + +export EMACSLOADPATH="${newLoadPath[*]}" + +exec @prog@ "$@" |