refactor Emacs packages'/modes' builders

This simplifies melpa builder by merging with it my old emacs modes builder,
adds better instructions and support for overrides in emacs-packages.nix,
and renames some emacs-related stuff in all-packages.nix for sanity reasons.

I declare this backwards compatible since direct uses of emacsPackages in
configuration.nix are very unlikely.
This commit is contained in:
Jan Malakhovski 2014-01-20 23:57:04 +00:00
parent a444eff3f2
commit e4a4e109ba
5 changed files with 136 additions and 75 deletions

View file

@ -0,0 +1,41 @@
# generic builder for Emacs packages
{ lib, stdenv, emacs, texinfo }:
with lib;
{ pname
, version ? null
, buildInputs ? []
, packageRequires ? []
, meta ? {}
, ...
}@args:
let
defaultMeta = {
broken = false;
platforms = emacs.meta.platforms;
};
in
stdenv.mkDerivation ({
name = "emacs-${pname}${optionalString (version != null) "-${version}"}";
buildInputs = [emacs texinfo] ++ packageRequires ++ buildInputs;
propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires;
setupHook = ./setup-hook.sh;
doCheck = false;
meta = defaultMeta // meta;
}
// removeAttrs args [ "buildInputs" "packageRequires"
"meta"
])

View file

@ -1,14 +1,12 @@
# generic builder for Emacs packages
# builder for Emacs packages built for packages.el
# using MELPA package-build.el
{ stdenv, fetchurl, emacs, texinfo
, extension ? (self : super : {})
}:
{ lib, stdenv, fetchurl, emacs, texinfo }:
with lib;
{ pname
, version
, src
, packageRequires ? []
, extraBuildInputs ? []
, files ? null
, fileSpecs ? [ "*.el" "*.el.in" "dir"
@ -18,19 +16,12 @@
, meta ? {}
, preUnpack ? "", postUnpack ? ""
, patches ? [], patchPhase ? "", prePatch ? "", postPatch ? ""
, configureFlags ? [], preConfigure ? "", postConfigure ? ""
, buildPhase ? "", preBuild ? "", postBuild ? ""
, preInstall ? "", postInstall ? ""
, doCheck ? false, checkPhase ? "", preCheck ? "", postCheck ? ""
, preFixup ? "", postFixup ? ""
}:
, ...
}@args:
let
inherit (stdenv.lib) concatStringsSep optionalAttrs;
packageBuild = fetchurl {
packageBuild = fetchurl {
url = https://raw.githubusercontent.com/milkypostman/melpa/12a862e5c5c62ce627dab83d7cf2cca6e8b56c47/package-build.el;
sha256 = "1nviyyprypz7nmam9rwli4yv3kxh170glfbznryrp4czxkrjjdhk";
};
@ -40,23 +31,13 @@ let
targets = concatStringsSep " " (if files == null then fileSpecs else files);
defaultMeta = {
broken = false;
homepage = "http://melpa.org/#/${pname}";
platforms = emacs.meta.platforms;
};
in
stdenv.mkDerivation ({
name = "emacs-${fname}";
inherit src packageBuild;
buildInputs = [emacs texinfo] ++ packageRequires ++ extraBuildInputs;
propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires;
setupHook = ./setup-hook.sh;
import ./generic.nix { inherit lib stdenv emacs texinfo; } ({
inherit packageBuild;
buildPhase = ''
runHook preBuild
@ -81,24 +62,6 @@ stdenv.mkDerivation ({
meta = defaultMeta // meta;
}
// optionalAttrs (preUnpack != "") { inherit preUnpack; }
// optionalAttrs (postUnpack != "") { inherit postUnpack; }
// optionalAttrs (configureFlags != []) { inherit configureFlags; }
// optionalAttrs (patches != []) { inherit patches; }
// optionalAttrs (patchPhase != "") { inherit patchPhase; }
// optionalAttrs (prePatch != "") { inherit prePatch; }
// optionalAttrs (postPatch != "") { inherit postPatch; }
// optionalAttrs (preConfigure != "") { inherit preConfigure; }
// optionalAttrs (postConfigure != "") { inherit postConfigure; }
// optionalAttrs (buildPhase != "") { inherit buildPhase; }
// optionalAttrs (preBuild != "") { inherit preBuild; }
// optionalAttrs (postBuild != "") { inherit postBuild; }
// optionalAttrs (doCheck) { inherit doCheck; }
// optionalAttrs (checkPhase != "") { inherit checkPhase; }
// optionalAttrs (preCheck != "") { inherit preCheck; }
// optionalAttrs (postCheck != "") { inherit postCheck; }
// optionalAttrs (preInstall != "") { inherit preInstall; }
// optionalAttrs (postInstall != "") { inherit postInstall; }
// optionalAttrs (preFixup != "") { inherit preFixup; }
// optionalAttrs (postFixup != "") { inherit postFixup; }
)
// removeAttrs args [ "files" "fileSpecs"
"meta"
])

View file

@ -0,0 +1,34 @@
# trivial builder for Emacs packages
{ lib, ... }@envargs:
with lib;
args:
import ./generic.nix envargs ({
#preConfigure = ''
# export LISPDIR=$out/share/emacs/site-lisp
# export VERSION_SPECIFIC_LISPDIR=$out/share/emacs/site-lisp
#'';
buildPhase = ''
eval "$preBuild"
emacs -L . --batch -f batch-byte-compile *.el
eval "$postBuild"
'';
installPhase = ''
eval "$preInstall"
LISPDIR=$out/share/emacs/site-lisp
install -d $LISPDIR
install *.el *.elc $LISPDIR
eval "$postInstall"
'';
}
// args)

View file

@ -9985,7 +9985,8 @@ let
emacs = emacs24;
emacsPackages = emacs24Packages;
emacsMelpa = emacs24Melpa;
emacsPackagesNg = emacs24PackagesNg;
emacsMelpa = emacs24PackagesNg; # for backward compatibility
emacs24 = callPackage ../applications/editors/emacs-24 {
# use override to enable additional features
@ -10173,14 +10174,25 @@ let
emacs24Packages = recurseIntoAttrs (emacsPackagesGen emacs24 pkgs.emacs24Packages);
emacsMelpaGen = emacs: import ./emacs-packages.nix {
inherit stdenv pkgs fetchurl fetchgit fetchFromGitHub emacs texinfo;
emacsPackagesNgGen = emacs: import ./emacs-packages.nix {
overrides = (config.emacsPackageOverrides or (p: {})) pkgs;
inherit lib stdenv fetchurl fetchgit fetchFromGitHub emacs;
trivialBuild = import ../build-support/emacs/trivial.nix {
inherit lib stdenv emacs texinfo;
};
melpaBuild = import ../build-support/emacs/melpa.nix {
inherit lib stdenv fetchurl emacs texinfo;
};
external = {
inherit (haskellngPackages) ghc-mod structured-haskell-mode;
};
};
emacs24Melpa = emacsMelpaGen emacs24;
emacs24PackagesNg = emacsPackagesNgGen emacs24;
inherit (gnome3) empathy;

View file

@ -1,27 +1,37 @@
{ pkgs, stdenv, fetchurl, fetchFromGitHub, fetchgit
, emacs, texinfo
# non-emacs packages
, external
}:
# package.el-based emacs packages
## init.el
#
## add this at the start your init.el:
# (require 'package)
# (setq package-archives nil
# package-user-dir "~/.nix-profile/share/emacs/site-lisp/elpa")
#
# ;; optional. makes unpure packages archives unavailable
# (setq package-archives nil)
#
# (add-to-list 'package-directory-list "/run/current-system/sw/share/emacs/site-lisp/elpa")
#
# ;; optional. use this if you install emacs packages to user profiles (with nix-env)
# (add-to-list 'package-directory-list "~/.nix-profile/share/emacs/site-lisp/elpa")
#
# (package-initialize)
with stdenv.lib.licences;
{ overrides
let
melpaBuild = import ../build-support/emacs/melpa.nix {
inherit stdenv fetchurl emacs texinfo;
};
in
, lib, stdenv, fetchurl, fetchgit, fetchFromGitHub
, emacs
, trivialBuild
, melpaBuild
, external
}@args:
with lib.licences;
let self = _self // overrides;
callPackage = lib.callPackageWith (self // removeAttrs args ["overrides" "external"]);
_self = with self; {
## START HERE
rec {
ac-haskell-process = melpaBuild rec {
pname = "ac-haskell-process";
version = "0.5";
@ -100,7 +110,7 @@ rec {
description = "Auto-complete extension for Emacs";
homepage = http://cx4a.org/software/auto-complete/;
license = gpl3Plus;
platforms = stdenv.lib.platforms.all;
platforms = lib.platforms.all;
};
};
@ -709,7 +719,7 @@ rec {
rev = "4cb2ced1eda5167ce774e04657d2cd077b63c706";
sha256 = "003sihp7irm0qqba778dx0gf8xhkxd1xk7ig5kgkryvl2jyirk28";
};
postPatch = stdenv.lib.optionalString (!stdenv.isLinux) ''
postPatch = lib.optionalString (!stdenv.isLinux) ''
rm weechat-sauron.el weechat-secrets.el
'';
packageRequires = [ s ];
@ -727,4 +737,5 @@ rec {
};
meta = { licence = gpl3Plus; };
};
}
}; in self