Merge pull request #15420 from samuelrivas/emacs-wrapper

emacs: hide wrapper dependencies
This commit is contained in:
Thomas Tuegel 2016-05-13 11:58:24 -05:00
commit 21efdd8003
3 changed files with 53 additions and 51 deletions

View File

@ -32,7 +32,7 @@ in customEmacsPackages.emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
*/ */
{ lib, lndir, makeWrapper, stdenv }: self: { lib, lndir, makeWrapper, runCommand, stdenv }: self:
with lib; let inherit (self) emacs; in with lib; let inherit (self) emacs; in
@ -49,13 +49,14 @@ stdenv.mkDerivation {
name = (appendToName "with-packages" emacs).name; name = (appendToName "with-packages" emacs).name;
nativeBuildInputs = [ emacs lndir makeWrapper ]; nativeBuildInputs = [ emacs lndir makeWrapper ];
inherit emacs explicitRequires; inherit emacs explicitRequires;
phases = [ "installPhase" ];
installPhase = ''
readonly SHARE="share/emacs-with-packages"
mkdir -p "$out/bin" # Store all paths we want to add to emacs here, so that we only need to add
mkdir -p "$out/$SHARE/bin" # one path to the load lists
mkdir -p "$out/$SHARE/site-lisp" deps = runCommand "emacs-packages-deps"
{ inherit explicitRequires lndir emacs; }
''
mkdir -p $out/bin
mkdir -p $out/share/emacs/site-lisp
local requires local requires
for pkg in $explicitRequires; do for pkg in $explicitRequires; do
@ -63,17 +64,6 @@ stdenv.mkDerivation {
done done
# requires now holds all requested packages and their transitive dependencies # requires now holds all requested packages and their transitive dependencies
siteStart="$out/$SHARE/site-lisp/site-start.el"
# 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/site-lisp")
(add-to-list 'exec-path "$out/$SHARE/bin")
EOF
linkPath() { linkPath() {
local pkg=$1 local pkg=$1
local origin_path=$2 local origin_path=$2
@ -81,35 +71,47 @@ EOF
# Add the path to the search path list, but only if it exists # Add the path to the search path list, but only if it exists
if [[ -d "$pkg/$origin_path" ]]; then if [[ -d "$pkg/$origin_path" ]]; then
lndir -silent "$pkg/$origin_path" "$out/$dest_path" $lndir/bin/lndir -silent "$pkg/$origin_path" "$out/$dest_path"
fi fi
} }
# Add a package's paths to site-start.el
linkEmacsPackage() { linkEmacsPackage() {
linkPath "$1" "bin" "$SHARE/bin" linkPath "$1" "bin" "bin"
linkPath "$1" "share/emacs/site-lisp" "$SHARE/site-lisp" linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp"
} }
# First, link all the explicitly-required packages.
for pkg in $explicitRequires; do
linkEmacsPackage $pkg
done
# Next, link all the dependencies.
for pkg in $requires; do for pkg in $requires; do
linkEmacsPackage $pkg linkEmacsPackage $pkg
done done
siteStart="$out/share/emacs/site-lisp/site-start.el"
# A dependency may have brought the original siteStart, delete it and
# create our own
# 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.
rm -f $siteStart
cat >"$siteStart" <<EOF
(load-file "$emacs/share/emacs/site-lisp/site-start.el")
(add-to-list 'load-path "$out/share/emacs/site-lisp")
(add-to-list 'exec-path "$out/bin")
EOF
# 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/bin/emacs --batch -f batch-byte-compile "$siteStart"
'';
phases = [ "installPhase" ];
installPhase = ''
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 # */
local progname=$(basename "$prog") local progname=$(basename "$prog")
rm -f "$out/bin/$progname" rm -f "$out/bin/$progname"
makeWrapper "$prog" "$out/bin/$progname" \ makeWrapper "$prog" "$out/bin/$progname" \
--suffix EMACSLOADPATH ":" "$out/$SHARE/site-lisp:" --suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:"
done done
mkdir -p $out/share mkdir -p $out/share

View File

@ -12399,7 +12399,7 @@ in
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 runCommand;
inherit (xorg) lndir; inherit (xorg) lndir;
trivialBuild = callPackage ../build-support/emacs/trivial.nix { trivialBuild = callPackage ../build-support/emacs/trivial.nix {

View File

@ -34,7 +34,7 @@
{ overrides { overrides
, lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg , lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg, runCommand
, emacs, texinfo, lndir, makeWrapper , emacs, texinfo, lndir, makeWrapper
, trivialBuild , trivialBuild
@ -64,7 +64,7 @@ let
}; };
emacsWithPackages = import ../build-support/emacs/wrapper.nix { emacsWithPackages = import ../build-support/emacs/wrapper.nix {
inherit lib lndir makeWrapper stdenv; inherit lib lndir makeWrapper stdenv runCommand;
}; };
packagesFun = self: with self; { packagesFun = self: with self; {