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 =
|
|
|
|
emacsPackagesNg.override (super: self: {
|
|
|
|
# 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-01-20 18:53:11 +00:00
|
|
|
{ lib, lndir, makeWrapper, stdenv }: self:
|
2015-04-17 17:24:27 +01:00
|
|
|
|
2015-12-17 02:53:12 +00:00
|
|
|
with lib; let inherit (self) emacs; in
|
2015-04-17 17:24:27 +01:00
|
|
|
|
2015-12-17 02:53:12 +00:00
|
|
|
packagesFun: # packages explicitly requested by the user
|
|
|
|
|
|
|
|
let
|
|
|
|
explicitRequires =
|
|
|
|
if builtins.isFunction packagesFun
|
|
|
|
then packagesFun self
|
|
|
|
else packagesFun;
|
|
|
|
in
|
2015-04-17 17:24:27 +01:00
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = (appendToName "with-packages" emacs).name;
|
2016-01-20 18:53:11 +00:00
|
|
|
nativeBuildInputs = [ emacs lndir makeWrapper ];
|
2015-04-17 17:24:27 +01:00
|
|
|
inherit emacs explicitRequires;
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
installPhase = ''
|
2016-04-03 20:21:50 +01:00
|
|
|
readonly SHARE="share/emacs-with-packages"
|
|
|
|
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
mkdir -p "$out/$SHARE/bin"
|
|
|
|
mkdir -p "$out/$SHARE/site-lisp"
|
2016-01-20 18:53:11 +00:00
|
|
|
|
2016-01-20 18:43:00 +00:00
|
|
|
local requires
|
2015-04-17 17:24:27 +01:00
|
|
|
for pkg in $explicitRequires; do
|
|
|
|
findInputs $pkg requires propagated-user-env-packages
|
|
|
|
done
|
|
|
|
# requires now holds all requested packages and their transitive dependencies
|
|
|
|
|
2016-04-03 20:21:50 +01:00
|
|
|
siteStart="$out/$SHARE/site-lisp/site-start.el"
|
2015-04-17 17:24:27 +01:00
|
|
|
|
2016-01-20 18:53:11 +00:00
|
|
|
# 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")
|
2016-04-03 20:21:50 +01:00
|
|
|
(add-to-list 'load-path "$out/$SHARE/site-lisp")
|
|
|
|
(add-to-list 'exec-path "$out/$SHARE/bin")
|
2016-01-20 18:53:11 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
linkPath() {
|
|
|
|
local pkg=$1
|
2016-04-03 20:11:38 +01:00
|
|
|
local origin_path=$2
|
|
|
|
local dest_path=$3
|
|
|
|
|
2015-04-17 17:24:27 +01:00
|
|
|
# Add the path to the search path list, but only if it exists
|
2016-04-03 20:11:38 +01:00
|
|
|
if [[ -d "$pkg/$origin_path" ]]; then
|
|
|
|
lndir -silent "$pkg/$origin_path" "$out/$dest_path"
|
2015-04-17 17:24:27 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-01-20 18:43:21 +00:00
|
|
|
# Add a package's paths to site-start.el
|
2016-01-20 18:53:11 +00:00
|
|
|
linkEmacsPackage() {
|
2016-04-03 20:21:50 +01:00
|
|
|
linkPath "$1" "bin" "$SHARE/bin"
|
|
|
|
linkPath "$1" "share/emacs/site-lisp" "$SHARE/site-lisp"
|
2015-04-17 17:24:27 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 18:53:11 +00:00
|
|
|
# First, link all the explicitly-required packages.
|
|
|
|
for pkg in $explicitRequires; do
|
|
|
|
linkEmacsPackage $pkg
|
2015-04-17 17:24:27 +01:00
|
|
|
done
|
|
|
|
|
2016-01-20 18:53:11 +00:00
|
|
|
# Next, link all the dependencies.
|
|
|
|
for pkg in $requires; do
|
|
|
|
linkEmacsPackage $pkg
|
2015-04-17 17:24:27 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Byte-compiling improves start-up time only slightly, but costs nothing.
|
|
|
|
emacs --batch -f batch-byte-compile "$siteStart"
|
|
|
|
|
|
|
|
# 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-04-03 20:21:50 +01:00
|
|
|
--suffix EMACSLOADPATH ":" "$out/$SHARE/site-lisp:"
|
2015-04-17 17:24:27 +01:00
|
|
|
done
|
2015-05-17 20:15:39 +01: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 17:24:27 +01:00
|
|
|
'';
|
|
|
|
inherit (emacs) meta;
|
|
|
|
}
|