2015-12-17 13:08:18 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
`emacsWithPackages` takes a single argument: a function from a package
|
|
|
|
set to a list of packages (the packages that will be available in
|
|
|
|
Emacs). For example,
|
|
|
|
```
|
|
|
|
emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
|
|
|
|
```
|
|
|
|
All the packages in the list should come from the provided package
|
|
|
|
set. It is possible to add any package to the list, but the provided
|
|
|
|
set is guaranteed to have consistent dependencies and be built with
|
|
|
|
the correct version of Emacs.
|
|
|
|
|
|
|
|
# Overriding
|
|
|
|
|
|
|
|
`emacsWithPackages` inherits the package set which contains it, so the
|
|
|
|
correct way to override the provided package set is to override the
|
|
|
|
set which contains `emacsWithPackages`. For example, to override
|
|
|
|
`emacsPackagesNg.emacsWithPackages`,
|
|
|
|
```
|
|
|
|
let customEmacsPackages =
|
2017-05-01 21:52:04 +00:00
|
|
|
emacsPackagesNg.overrideScope (super: self: {
|
2015-12-17 13:08:18 +00:00
|
|
|
# use a custom version of emacs
|
|
|
|
emacs = ...;
|
|
|
|
# use the unstable MELPA version of magit
|
|
|
|
magit = self.melpaPackages.magit;
|
|
|
|
});
|
|
|
|
in customEmacsPackages.emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
|
|
|
|
```
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-05-12 20:15:40 +00:00
|
|
|
{ lib, lndir, makeWrapper, runCommand, stdenv }: self:
|
2015-04-17 16:24:27 +00:00
|
|
|
|
2015-12-17 02:53:12 +00:00
|
|
|
with lib; let inherit (self) emacs; in
|
2015-04-17 16:24:27 +00:00
|
|
|
|
2016-08-19 20:09:41 +00:00
|
|
|
packagesFun: # packages explicitly requested by the user
|
2015-12-17 02:53:12 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
explicitRequires =
|
|
|
|
if builtins.isFunction packagesFun
|
|
|
|
then packagesFun self
|
|
|
|
else packagesFun;
|
|
|
|
in
|
2015-04-17 16:24:27 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = (appendToName "with-packages" emacs).name;
|
2016-01-20 18:53:11 +00:00
|
|
|
nativeBuildInputs = [ emacs lndir makeWrapper ];
|
2015-04-17 16:24:27 +00:00
|
|
|
inherit emacs explicitRequires;
|
|
|
|
|
2016-05-12 20:15:40 +00:00
|
|
|
# Store all paths we want to add to emacs here, so that we only need to add
|
|
|
|
# one path to the load lists
|
|
|
|
deps = runCommand "emacs-packages-deps"
|
2016-08-19 20:09:41 +00:00
|
|
|
{ inherit explicitRequires lndir emacs; }
|
2016-05-12 20:15:40 +00:00
|
|
|
''
|
|
|
|
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
|
|
|
|
done
|
|
|
|
# requires now holds all requested packages and their transitive dependencies
|
|
|
|
|
|
|
|
linkPath() {
|
|
|
|
local pkg=$1
|
|
|
|
local origin_path=$2
|
|
|
|
local dest_path=$3
|
|
|
|
|
|
|
|
# Add the path to the search path list, but only if it exists
|
|
|
|
if [[ -d "$pkg/$origin_path" ]]; then
|
|
|
|
$lndir/bin/lndir -silent "$pkg/$origin_path" "$out/$dest_path"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
linkEmacsPackage() {
|
|
|
|
linkPath "$1" "bin" "bin"
|
|
|
|
linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp"
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:24:55 +00:00
|
|
|
# Iterate over the array of inputs (avoiding nix's own interpolation)
|
|
|
|
for pkg in "''${requires[@]}"; do
|
2016-05-12 20:15:40 +00:00
|
|
|
linkEmacsPackage $pkg
|
|
|
|
done
|
|
|
|
|
|
|
|
siteStart="$out/share/emacs/site-lisp/site-start.el"
|
2016-09-27 20:13:22 +00:00
|
|
|
siteStartByteCompiled="$siteStart"c
|
2016-05-12 20:15:40 +00:00
|
|
|
|
|
|
|
# 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.
|
2016-09-27 20:13:22 +00:00
|
|
|
rm -f $siteStart $siteStartByteCompiled
|
2016-05-12 20:15:40 +00:00
|
|
|
cat >"$siteStart" <<EOF
|
2016-01-20 18:53:11 +00:00
|
|
|
(load-file "$emacs/share/emacs/site-lisp/site-start.el")
|
2016-05-12 20:15:40 +00:00
|
|
|
(add-to-list 'load-path "$out/share/emacs/site-lisp")
|
|
|
|
(add-to-list 'exec-path "$out/bin")
|
2016-01-20 18:53:11 +00:00
|
|
|
EOF
|
|
|
|
|
2016-05-12 20:15:40 +00:00
|
|
|
# Byte-compiling improves start-up time only slightly, but costs nothing.
|
|
|
|
$emacs/bin/emacs --batch -f batch-byte-compile "$siteStart"
|
|
|
|
'';
|
2015-04-17 16:24:27 +00:00
|
|
|
|
2016-05-12 20:15:40 +00:00
|
|
|
phases = [ "installPhase" ];
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p "$out/bin"
|
2015-04-17 16:24:27 +00:00
|
|
|
|
|
|
|
# Wrap emacs and friends so they find our site-start.el before the original.
|
|
|
|
for prog in $emacs/bin/*; do # */
|
2016-01-20 18:53:11 +00:00
|
|
|
local progname=$(basename "$prog")
|
|
|
|
rm -f "$out/bin/$progname"
|
|
|
|
makeWrapper "$prog" "$out/bin/$progname" \
|
2016-05-12 20:15:40 +00:00
|
|
|
--suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:"
|
2015-04-17 16:24:27 +00:00
|
|
|
done
|
2015-05-17 19:15:39 +00:00
|
|
|
|
2017-05-20 23:51:32 +00:00
|
|
|
# Wrap MacOS app
|
|
|
|
# this has to pick up resources and metadata
|
|
|
|
# to recognize it as an "app"
|
|
|
|
if [ -d "$emacs/Applications/Emacs.app" ]; then
|
|
|
|
mkdir -p $out/Applications/Emacs.app/Contents/MacOS
|
|
|
|
cp -r $emacs/Applications/Emacs.app/Contents/Info.plist \
|
|
|
|
$emacs/Applications/Emacs.app/Contents/PkgInfo \
|
|
|
|
$emacs/Applications/Emacs.app/Contents/Resources \
|
|
|
|
$out/Applications/Emacs.app/Contents
|
|
|
|
makeWrapper $emacs/Applications/Emacs.app/Contents/MacOS/Emacs $out/Applications/Emacs.app/Contents/MacOS/Emacs \
|
|
|
|
--suffix EMACSLOADPATH ":" "$deps/share/emacs/site-lisp:"
|
|
|
|
fi
|
|
|
|
|
2015-05-17 19:15:39 +00:00
|
|
|
mkdir -p $out/share
|
|
|
|
# Link icons and desktop files into place
|
|
|
|
for dir in applications icons info man; do
|
|
|
|
ln -s $emacs/share/$dir $out/share/$dir
|
|
|
|
done
|
2015-04-17 16:24:27 +00:00
|
|
|
'';
|
|
|
|
inherit (emacs) meta;
|
|
|
|
}
|