Merge pull request #12738 from ttuegel/emacsWithPackages
Reduce load time of emacsWithPackages
This commit is contained in:
commit
1e5cad9c8c
|
@ -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
|
with lib; let inherit (self) emacs; in
|
||||||
|
|
||||||
|
@ -47,11 +47,14 @@ in
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = (appendToName "with-packages" emacs).name;
|
name = (appendToName "with-packages" emacs).name;
|
||||||
nativeBuildInputs = [ emacs makeWrapper ];
|
nativeBuildInputs = [ emacs lndir makeWrapper ];
|
||||||
inherit emacs explicitRequires;
|
inherit emacs explicitRequires;
|
||||||
phases = [ "installPhase" ];
|
phases = [ "installPhase" ];
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
requires=""
|
mkdir -p $out/bin
|
||||||
|
mkdir -p $out/share/emacs/site-lisp
|
||||||
|
|
||||||
|
local requires
|
||||||
for pkg in $explicitRequires; do
|
for pkg in $explicitRequires; do
|
||||||
findInputs $pkg requires propagated-user-env-packages
|
findInputs $pkg requires propagated-user-env-packages
|
||||||
done
|
done
|
||||||
|
@ -59,52 +62,47 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
siteStart="$out/share/emacs/site-lisp/site-start.el"
|
siteStart="$out/share/emacs/site-lisp/site-start.el"
|
||||||
|
|
||||||
addEmacsPath() {
|
|
||||||
local list=$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"
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir -p $out/share/emacs/site-lisp
|
|
||||||
# Begin the new site-start.el by loading the original, which sets some
|
# 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
|
# 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.
|
# 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"
|
cat >"$siteStart" <<EOF
|
||||||
echo "(require 'package)" >>"$siteStart"
|
(load-file "$emacs/share/emacs/site-lisp/site-start.el")
|
||||||
|
(add-to-list 'load-path "$out/share/emacs/site-lisp")
|
||||||
|
EOF
|
||||||
|
|
||||||
# Set paths for the dependencies of the requested packages. These paths are
|
linkPath() {
|
||||||
# searched before the profile paths, but after the explicitly-required paths.
|
local pkg=$1
|
||||||
for pkg in $requires; do
|
local path=$2
|
||||||
# The explicitly-required packages are also in the list, but we will add
|
# Add the path to the search path list, but only if it exists
|
||||||
# those paths last.
|
if [[ -d "$pkg/$path" ]]; then
|
||||||
if ! ( echo "$explicitRequires" | grep "$pkg" >/dev/null ) ; then
|
lndir -silent "$pkg/$path" "$out/$path"
|
||||||
addToEmacsPaths $pkg
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add a package's paths to site-start.el
|
||||||
|
linkEmacsPackage() {
|
||||||
|
linkPath "$1" "bin"
|
||||||
|
linkPath "$1" "share/emacs/site-lisp"
|
||||||
|
}
|
||||||
|
|
||||||
|
# First, link all the explicitly-required packages.
|
||||||
|
for pkg in $explicitRequires; do
|
||||||
|
linkEmacsPackage $pkg
|
||||||
done
|
done
|
||||||
|
|
||||||
# Finally, add paths for all the explicitly-required packages. These paths
|
# Next, link all the dependencies.
|
||||||
# will be searched first.
|
for pkg in $requires; do
|
||||||
for pkg in $explicitRequires; do
|
linkEmacsPackage $pkg
|
||||||
addToEmacsPaths $pkg
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Byte-compiling improves start-up time only slightly, but costs nothing.
|
# Byte-compiling improves start-up time only slightly, but costs nothing.
|
||||||
emacs --batch -f batch-byte-compile "$siteStart"
|
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.
|
# Wrap emacs and friends so they find our site-start.el before the original.
|
||||||
for prog in $emacs/bin/*; do # */
|
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:"
|
--suffix EMACSLOADPATH ":" "$out/share/emacs/site-lisp:"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -11794,6 +11794,7 @@ let
|
||||||
inherit lib newScope stdenv;
|
inherit lib newScope stdenv;
|
||||||
inherit fetchFromGitHub fetchgit fetchhg fetchurl;
|
inherit fetchFromGitHub fetchgit fetchhg fetchurl;
|
||||||
inherit emacs texinfo makeWrapper;
|
inherit emacs texinfo makeWrapper;
|
||||||
|
inherit (xorg) lndir;
|
||||||
|
|
||||||
trivialBuild = callPackage ../build-support/emacs/trivial.nix {
|
trivialBuild = callPackage ../build-support/emacs/trivial.nix {
|
||||||
inherit emacs;
|
inherit emacs;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
, lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg
|
, lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg
|
||||||
|
|
||||||
, emacs, texinfo, makeWrapper
|
, emacs, texinfo, lndir, makeWrapper
|
||||||
, trivialBuild
|
, trivialBuild
|
||||||
, melpaBuild
|
, melpaBuild
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
emacsWithPackages = import ../build-support/emacs/wrapper.nix {
|
emacsWithPackages = import ../build-support/emacs/wrapper.nix {
|
||||||
inherit lib makeWrapper stdenv;
|
inherit lib lndir makeWrapper stdenv;
|
||||||
};
|
};
|
||||||
|
|
||||||
packagesFun = self: with self; {
|
packagesFun = self: with self; {
|
||||||
|
|
Loading…
Reference in New Issue