···3233*/
3435-{ lib, lndir, makeWrapper, stdenv }: self:
3637with lib; let inherit (self) emacs; in
38···49 name = (appendToName "with-packages" emacs).name;
50 nativeBuildInputs = [ emacs lndir makeWrapper ];
51 inherit emacs explicitRequires;
52- phases = [ "installPhase" ];
53- installPhase = ''
54- readonly SHARE="share/emacs-with-packages"
5556- mkdir -p "$out/bin"
57- mkdir -p "$out/$SHARE/bin"
58- mkdir -p "$out/$SHARE/site-lisp"
00005960- 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
6566- siteStart="$out/$SHARE/site-lisp/site-start.el"
0006768- # 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
7677- linkPath() {
78- local pkg=$1
79- local origin_path=$2
80- local dest_path=$3
8182- # 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- }
8788- # 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- }
9394- # First, link all the explicitly-required packages.
95- for pkg in $explicitRequires; do
96- linkEmacsPackage $pkg
97- done
00000009899- # Next, link all the dependencies.
100- for pkg in $requires; do
101- linkEmacsPackage $pkg
102- done
103104- # Byte-compiling improves start-up time only slightly, but costs nothing.
105- emacs --batch -f batch-byte-compile "$siteStart"
0106107 # Wrap emacs and friends so they find our site-start.el before the original.
108 for prog in $emacs/bin/*; do # */
109 local progname=$(basename "$prog")
110 rm -f "$out/bin/$progname"
111 makeWrapper "$prog" "$out/bin/$progname" \
112- --suffix EMACSLOADPATH ":" "$out/$SHARE/site-lisp:"
113 done
114115 mkdir -p $out/share
···3233*/
3435+{ lib, lndir, makeWrapper, runCommand, stdenv }: self:
3637with lib; let inherit (self) emacs; in
38···49 name = (appendToName "with-packages" emacs).name;
50 nativeBuildInputs = [ emacs lndir makeWrapper ];
51 inherit emacs explicitRequires;
0005253+ # 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
6061+ 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
6667+ linkPath() {
68+ local pkg=$1
69+ local origin_path=$2
70+ local dest_path=$3
7172+ # 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+ }
0007778+ linkEmacsPackage() {
79+ linkPath "$1" "bin" "bin"
80+ linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp"
81+ }
8283+ for pkg in $requires; do
84+ linkEmacsPackage $pkg
85+ done
008687+ siteStart="$out/share/emacs/site-lisp/site-start.el"
00008889+ # 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
100101+ # Byte-compiling improves start-up time only slightly, but costs nothing.
102+ $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart"
103+ '';
0104105+ phases = [ "installPhase" ];
106+ installPhase = ''
107+ mkdir -p "$out/bin"
108109 # Wrap emacs and friends so they find our site-start.el before the original.
110 for prog in $emacs/bin/*; do # */
111 local progname=$(basename "$prog")
112 rm -f "$out/bin/$progname"
113 makeWrapper "$prog" "$out/bin/$progname" \
114+ --suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:"
115 done
116117 mkdir -p $out/share