From e4a4e109ba49f3868f63a61e514c4846a1cd0b9a Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Mon, 20 Jan 2014 23:57:04 +0000 Subject: [PATCH] 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. --- pkgs/build-support/emacs/generic.nix | 41 ++++++++++++++++++ pkgs/build-support/emacs/melpa.nix | 63 ++++++---------------------- pkgs/build-support/emacs/trivial.nix | 34 +++++++++++++++ pkgs/top-level/all-packages.nix | 20 +++++++-- pkgs/top-level/emacs-packages.nix | 53 +++++++++++++---------- 5 files changed, 136 insertions(+), 75 deletions(-) create mode 100644 pkgs/build-support/emacs/generic.nix create mode 100644 pkgs/build-support/emacs/trivial.nix diff --git a/pkgs/build-support/emacs/generic.nix b/pkgs/build-support/emacs/generic.nix new file mode 100644 index 000000000000..be81e93e32ae --- /dev/null +++ b/pkgs/build-support/emacs/generic.nix @@ -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" + ]) diff --git a/pkgs/build-support/emacs/melpa.nix b/pkgs/build-support/emacs/melpa.nix index 11cb14f93db4..607a1b4a5ef6 100644 --- a/pkgs/build-support/emacs/melpa.nix +++ b/pkgs/build-support/emacs/melpa.nix @@ -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" + ]) diff --git a/pkgs/build-support/emacs/trivial.nix b/pkgs/build-support/emacs/trivial.nix new file mode 100644 index 000000000000..9c97e8bf9514 --- /dev/null +++ b/pkgs/build-support/emacs/trivial.nix @@ -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) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b5eed339f465..78c9b3195c66 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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; diff --git a/pkgs/top-level/emacs-packages.nix b/pkgs/top-level/emacs-packages.nix index 0be7a3adf470..9f7c9675cb0f 100644 --- a/pkgs/top-level/emacs-packages.nix +++ b/pkgs/top-level/emacs-packages.nix @@ -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