summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@gmail.com>2016-01-31 17:28:20 -0600
committerThomas Tuegel <ttuegel@gmail.com>2016-01-31 17:28:20 -0600
commit1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed (patch)
tree8e411d8808ac66870f916c37efb7033c67ba4dba /pkgs/build-support
parent35ca5a98ba50c66678f5427d941b43869192c7d2 (diff)
parent32c30411cfbb6e26512a299fe4830bed05b67b3e (diff)
downloadnixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar.gz
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar.bz2
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar.lz
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar.xz
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.tar.zst
nixlib-1e5cad9c8c5e679ea2db9924eeceb3aee592e6ed.zip
Merge pull request #12738 from ttuegel/emacsWithPackages
Reduce load time of emacsWithPackages
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/emacs/wrapper.nix64
1 files changed, 31 insertions, 33 deletions
diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix
index dc4ff03f9e78..efee43d852ea 100644
--- a/pkgs/build-support/emacs/wrapper.nix
+++ b/pkgs/build-support/emacs/wrapper.nix
@@ -32,7 +32,7 @@ in customEmacsPackages.emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
 
 */
 
-{ lib, makeWrapper, stdenv }: self:
+{ lib, lndir, makeWrapper, stdenv }: self:
 
 with lib; let inherit (self) emacs; in
 
@@ -47,11 +47,14 @@ in
 
 stdenv.mkDerivation {
   name = (appendToName "with-packages" emacs).name;
-  nativeBuildInputs = [ emacs makeWrapper ];
+  nativeBuildInputs = [ emacs lndir makeWrapper ];
   inherit emacs explicitRequires;
   phases = [ "installPhase" ];
   installPhase = ''
-    requires=""
+    mkdir -p $out/bin
+    mkdir -p $out/share/emacs/site-lisp
+
+    local requires
     for pkg in $explicitRequires; do
       findInputs $pkg requires propagated-user-env-packages
     done
@@ -59,52 +62,47 @@ stdenv.mkDerivation {
 
     siteStart="$out/share/emacs/site-lisp/site-start.el"
 
-    addEmacsPath() {
-      local list=$1
+    # Begin the new site-start.el by loading the original, which sets some
+    # NixOS-specific paths. Paths are searched in the reverse of the order
+    # they are specified in, so user and system profile paths are searched last.
+    cat >"$siteStart" <<EOF
+(load-file "$emacs/share/emacs/site-lisp/site-start.el")
+(add-to-list 'load-path "$out/share/emacs/site-lisp")
+EOF
+
+    linkPath() {
+      local pkg=$1
       local path=$2
       # Add the path to the search path list, but only if it exists
-      if [[ -d "$path" ]]; then
-        echo "(add-to-list '$list \"$path\")" >>"$siteStart"
+      if [[ -d "$pkg/$path" ]]; then
+        lndir -silent "$pkg/$path" "$out/$path"
       fi
     }
 
-    # Add a dependency's paths to site-start.el
-    addToEmacsPaths() {
-      addEmacsPath "exec-path" "$1/bin"
-      addEmacsPath "load-path" "$1/share/emacs/site-lisp"
-      addEmacsPath "package-directory-list" "$1/share/emacs/site-lisp/elpa"
+    # Add a package's paths to site-start.el
+    linkEmacsPackage() {
+      linkPath "$1" "bin"
+      linkPath "$1" "share/emacs/site-lisp"
     }
 
-    mkdir -p $out/share/emacs/site-lisp
-    # Begin the new site-start.el by loading the original, which sets some
-    # NixOS-specific paths. Paths are searched in the reverse of the order
-    # they are specified in, so user and system profile paths are searched last.
-    echo "(load-file \"$emacs/share/emacs/site-lisp/site-start.el\")" >"$siteStart"
-    echo "(require 'package)" >>"$siteStart"
-
-    # Set paths for the dependencies of the requested packages. These paths are
-    # searched before the profile paths, but after the explicitly-required paths.
-    for pkg in $requires; do
-      # The explicitly-required packages are also in the list, but we will add
-      # those paths last.
-      if ! ( echo "$explicitRequires" | grep "$pkg" >/dev/null ) ; then
-        addToEmacsPaths $pkg
-      fi
+    # First, link all the explicitly-required packages.
+    for pkg in $explicitRequires; do
+      linkEmacsPackage $pkg
     done
 
-    # Finally, add paths for all the explicitly-required packages. These paths
-    # will be searched first.
-    for pkg in $explicitRequires; do
-      addToEmacsPaths $pkg
+    # Next, link all the dependencies.
+    for pkg in $requires; do
+      linkEmacsPackage $pkg
     done
 
     # Byte-compiling improves start-up time only slightly, but costs nothing.
     emacs --batch -f batch-byte-compile "$siteStart"
 
-    mkdir -p $out/bin
     # Wrap emacs and friends so they find our site-start.el before the original.
     for prog in $emacs/bin/*; do # */
-      makeWrapper "$prog" $out/bin/$(basename "$prog") \
+      local progname=$(basename "$prog")
+      rm -f "$out/bin/$progname"
+      makeWrapper "$prog" "$out/bin/$progname" \
         --suffix EMACSLOADPATH ":" "$out/share/emacs/site-lisp:"
     done