Merge pull request #15420 from samuelrivas/emacs-wrapper

emacs: hide wrapper dependencies

+51 -49
+48 -46
pkgs/build-support/emacs/wrapper.nix
··· 32 32 33 33 */ 34 34 35 - { lib, lndir, makeWrapper, stdenv }: self: 35 + { lib, lndir, makeWrapper, runCommand, stdenv }: self: 36 36 37 37 with lib; let inherit (self) emacs; in 38 38 ··· 49 49 name = (appendToName "with-packages" emacs).name; 50 50 nativeBuildInputs = [ emacs lndir makeWrapper ]; 51 51 inherit emacs explicitRequires; 52 - phases = [ "installPhase" ]; 53 - installPhase = '' 54 - readonly SHARE="share/emacs-with-packages" 55 52 56 - mkdir -p "$out/bin" 57 - mkdir -p "$out/$SHARE/bin" 58 - mkdir -p "$out/$SHARE/site-lisp" 53 + # Store all paths we want to add to emacs here, so that we only need to add 54 + # one path to the load lists 55 + deps = runCommand "emacs-packages-deps" 56 + { inherit explicitRequires lndir emacs; } 57 + '' 58 + mkdir -p $out/bin 59 + mkdir -p $out/share/emacs/site-lisp 59 60 60 - local requires 61 - for pkg in $explicitRequires; do 62 - findInputs $pkg requires propagated-user-env-packages 63 - done 64 - # requires now holds all requested packages and their transitive dependencies 61 + local requires 62 + for pkg in $explicitRequires; do 63 + findInputs $pkg requires propagated-user-env-packages 64 + done 65 + # requires now holds all requested packages and their transitive dependencies 65 66 66 - siteStart="$out/$SHARE/site-lisp/site-start.el" 67 + linkPath() { 68 + local pkg=$1 69 + local origin_path=$2 70 + local dest_path=$3 67 71 68 - # Begin the new site-start.el by loading the original, which sets some 69 - # NixOS-specific paths. Paths are searched in the reverse of the order 70 - # they are specified in, so user and system profile paths are searched last. 71 - cat >"$siteStart" <<EOF 72 - (load-file "$emacs/share/emacs/site-lisp/site-start.el") 73 - (add-to-list 'load-path "$out/$SHARE/site-lisp") 74 - (add-to-list 'exec-path "$out/$SHARE/bin") 75 - EOF 72 + # Add the path to the search path list, but only if it exists 73 + if [[ -d "$pkg/$origin_path" ]]; then 74 + $lndir/bin/lndir -silent "$pkg/$origin_path" "$out/$dest_path" 75 + fi 76 + } 76 77 77 - linkPath() { 78 - local pkg=$1 79 - local origin_path=$2 80 - local dest_path=$3 78 + linkEmacsPackage() { 79 + linkPath "$1" "bin" "bin" 80 + linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp" 81 + } 81 82 82 - # Add the path to the search path list, but only if it exists 83 - if [[ -d "$pkg/$origin_path" ]]; then 84 - lndir -silent "$pkg/$origin_path" "$out/$dest_path" 85 - fi 86 - } 83 + for pkg in $requires; do 84 + linkEmacsPackage $pkg 85 + done 87 86 88 - # Add a package's paths to site-start.el 89 - linkEmacsPackage() { 90 - linkPath "$1" "bin" "$SHARE/bin" 91 - linkPath "$1" "share/emacs/site-lisp" "$SHARE/site-lisp" 92 - } 87 + siteStart="$out/share/emacs/site-lisp/site-start.el" 93 88 94 - # First, link all the explicitly-required packages. 95 - for pkg in $explicitRequires; do 96 - linkEmacsPackage $pkg 97 - done 89 + # A dependency may have brought the original siteStart, delete it and 90 + # create our own 91 + # Begin the new site-start.el by loading the original, which sets some 92 + # NixOS-specific paths. Paths are searched in the reverse of the order 93 + # they are specified in, so user and system profile paths are searched last. 94 + rm -f $siteStart 95 + cat >"$siteStart" <<EOF 96 + (load-file "$emacs/share/emacs/site-lisp/site-start.el") 97 + (add-to-list 'load-path "$out/share/emacs/site-lisp") 98 + (add-to-list 'exec-path "$out/bin") 99 + EOF 98 100 99 - # Next, link all the dependencies. 100 - for pkg in $requires; do 101 - linkEmacsPackage $pkg 102 - done 101 + # Byte-compiling improves start-up time only slightly, but costs nothing. 102 + $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" 103 + ''; 103 104 104 - # Byte-compiling improves start-up time only slightly, but costs nothing. 105 - emacs --batch -f batch-byte-compile "$siteStart" 105 + phases = [ "installPhase" ]; 106 + installPhase = '' 107 + mkdir -p "$out/bin" 106 108 107 109 # Wrap emacs and friends so they find our site-start.el before the original. 108 110 for prog in $emacs/bin/*; do # */ 109 111 local progname=$(basename "$prog") 110 112 rm -f "$out/bin/$progname" 111 113 makeWrapper "$prog" "$out/bin/$progname" \ 112 - --suffix EMACSLOADPATH ":" "$out/$SHARE/site-lisp:" 114 + --suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:" 113 115 done 114 116 115 117 mkdir -p $out/share
+1 -1
pkgs/top-level/all-packages.nix
··· 12399 12399 12400 12400 inherit lib newScope stdenv; 12401 12401 inherit fetchFromGitHub fetchgit fetchhg fetchurl; 12402 - inherit emacs texinfo makeWrapper; 12402 + inherit emacs texinfo makeWrapper runCommand; 12403 12403 inherit (xorg) lndir; 12404 12404 12405 12405 trivialBuild = callPackage ../build-support/emacs/trivial.nix {
+2 -2
pkgs/top-level/emacs-packages.nix
··· 34 34 35 35 { overrides 36 36 37 - , lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg 37 + , lib, newScope, stdenv, fetchurl, fetchgit, fetchFromGitHub, fetchhg, runCommand 38 38 39 39 , emacs, texinfo, lndir, makeWrapper 40 40 , trivialBuild ··· 64 64 }; 65 65 66 66 emacsWithPackages = import ../build-support/emacs/wrapper.nix { 67 - inherit lib lndir makeWrapper stdenv; 67 + inherit lib lndir makeWrapper stdenv runCommand; 68 68 }; 69 69 70 70 packagesFun = self: with self; {