From 97e1258dedf64bc4049d572f5d2e756dd6c5dfa6 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Wed, 20 Jan 2016 12:43:00 -0600 Subject: [PATCH 1/3] emacsWithPackages: use local variables correctly --- pkgs/build-support/emacs/wrapper.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index dc4ff03f9e7..742b2cf5cde 100644 --- a/pkgs/build-support/emacs/wrapper.nix +++ b/pkgs/build-support/emacs/wrapper.nix @@ -51,7 +51,7 @@ stdenv.mkDerivation { inherit emacs explicitRequires; phases = [ "installPhase" ]; installPhase = '' - requires="" + local requires for pkg in $explicitRequires; do findInputs $pkg requires propagated-user-env-packages done From 2b1024646b42958a874446ec7155cc6c6b247d78 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Wed, 20 Jan 2016 12:43:21 -0600 Subject: [PATCH 2/3] emacsWithPackages: defer loading package.el Also stops duplicating load paths. --- pkgs/build-support/emacs/wrapper.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index 742b2cf5cde..ad1a54886a6 100644 --- a/pkgs/build-support/emacs/wrapper.nix +++ b/pkgs/build-support/emacs/wrapper.nix @@ -68,11 +68,10 @@ stdenv.mkDerivation { fi } - # Add a dependency's paths to site-start.el - addToEmacsPaths() { + # Add a package's paths to site-start.el + addEmacsPackage() { 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 @@ -80,7 +79,6 @@ stdenv.mkDerivation { # 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. @@ -88,14 +86,14 @@ stdenv.mkDerivation { # 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 + addEmacsPackage $pkg fi done # Finally, add paths for all the explicitly-required packages. These paths # will be searched first. for pkg in $explicitRequires; do - addToEmacsPaths $pkg + addEmacsPackage $pkg done # Byte-compiling improves start-up time only slightly, but costs nothing. From 32c30411cfbb6e26512a299fe4830bed05b67b3e Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Wed, 20 Jan 2016 12:53:11 -0600 Subject: [PATCH 3/3] emacsWithPackages: link packages into single load-path This should provide a small speed improvement by avoiding having to set hundreds of load-paths. --- pkgs/build-support/emacs/wrapper.nix | 58 ++++++++++++++-------------- pkgs/top-level/all-packages.nix | 1 + pkgs/top-level/emacs-packages.nix | 4 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index ad1a54886a6..efee43d852e 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,10 +47,13 @@ in stdenv.mkDerivation { name = (appendToName "with-packages" emacs).name; - nativeBuildInputs = [ emacs makeWrapper ]; + nativeBuildInputs = [ emacs lndir makeWrapper ]; inherit emacs explicitRequires; phases = [ "installPhase" ]; installPhase = '' + 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 @@ -59,50 +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" <>"$siteStart" + if [[ -d "$pkg/$path" ]]; then + lndir -silent "$pkg/$path" "$out/$path" fi } # Add a package's paths to site-start.el - addEmacsPackage() { - addEmacsPath "exec-path" "$1/bin" - addEmacsPath "load-path" "$1/share/emacs/site-lisp" + 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" - - # 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 - addEmacsPackage $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 - addEmacsPackage $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 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 91f74bc3056..d6aff308635 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11720,6 +11720,7 @@ let inherit lib newScope stdenv; inherit fetchFromGitHub fetchgit fetchhg fetchurl; inherit emacs texinfo makeWrapper; + inherit (xorg) lndir; trivialBuild = callPackage ../build-support/emacs/trivial.nix { inherit emacs; diff --git a/pkgs/top-level/emacs-packages.nix b/pkgs/top-level/emacs-packages.nix index 0bd7b0efad3..896e324c51b 100644 --- a/pkgs/top-level/emacs-packages.nix +++ b/pkgs/top-level/emacs-packages.nix @@ -36,7 +36,7 @@ , lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg -, emacs, texinfo, makeWrapper +, emacs, texinfo, lndir, makeWrapper , trivialBuild , melpaBuild @@ -60,7 +60,7 @@ let }; emacsWithPackages = import ../build-support/emacs/wrapper.nix { - inherit lib makeWrapper stdenv; + inherit lib lndir makeWrapper stdenv; }; packagesFun = self: with self; {