2017-01-07 18:16:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.emacs;
|
|
|
|
|
2018-12-17 22:01:43 +00:00
|
|
|
# Copied from all-packages.nix, with modifications to support
|
|
|
|
# overrides.
|
2020-06-06 12:12:45 +00:00
|
|
|
emacsPackages = let epkgs = pkgs.emacsPackagesFor cfg.package;
|
2020-05-24 22:45:51 +00:00
|
|
|
in epkgs.overrideScope' cfg.overrides;
|
2017-09-19 21:32:01 +00:00
|
|
|
|
2020-05-24 22:45:51 +00:00
|
|
|
emacsWithPackages = emacsPackages.emacsWithPackages;
|
2017-01-07 18:16:26 +00:00
|
|
|
|
2021-01-29 16:43:49 +00:00
|
|
|
createConfPackage = epkgs:
|
|
|
|
epkgs.trivialBuild {
|
|
|
|
pname = "default";
|
|
|
|
src = pkgs.writeText "default.el" cfg.extraConfig;
|
|
|
|
};
|
|
|
|
|
2020-05-24 22:45:51 +00:00
|
|
|
in {
|
2017-09-26 21:40:31 +00:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
options = {
|
|
|
|
programs.emacs = {
|
|
|
|
enable = mkEnableOption "Emacs";
|
|
|
|
|
2017-09-19 21:32:01 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.emacs;
|
2019-08-27 22:12:28 +00:00
|
|
|
defaultText = literalExample "pkgs.emacs";
|
2017-09-19 21:32:01 +00:00
|
|
|
example = literalExample "pkgs.emacs25-nox";
|
|
|
|
description = "The Emacs package to use.";
|
|
|
|
};
|
|
|
|
|
2021-01-29 16:43:49 +00:00
|
|
|
# NOTE: The config is placed in default.el instead of ~/.emacs.d so that
|
|
|
|
# it won't conflict with Emacs configuration frameworks. Users of these
|
|
|
|
# frameworks would still benefit from this option as it would easily allow
|
|
|
|
# them to have Nix-computed paths in their configuration.
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
(setq standard-indent 2)
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration to include in the Emacs default init file. See
|
|
|
|
<link xlink:href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Init-File.html"/>
|
|
|
|
for more.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
extraPackages = mkOption {
|
2020-05-24 22:45:51 +00:00
|
|
|
default = self: [ ];
|
2020-01-26 10:26:33 +00:00
|
|
|
type = hm.types.selectorFunction;
|
2017-11-12 23:03:49 +00:00
|
|
|
defaultText = "epkgs: []";
|
|
|
|
example = literalExample "epkgs: [ epkgs.emms epkgs.magit ]";
|
2019-08-18 11:33:34 +00:00
|
|
|
description = ''
|
|
|
|
Extra packages available to Emacs. To get a list of
|
|
|
|
available packages run:
|
2019-11-04 11:16:06 +00:00
|
|
|
<command>nix-env -f '<nixpkgs>' -qaP -A emacsPackages</command>.
|
2019-08-18 11:33:34 +00:00
|
|
|
'';
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
2018-09-11 19:23:11 +00:00
|
|
|
|
2018-12-17 22:01:43 +00:00
|
|
|
overrides = mkOption {
|
2020-05-24 22:45:51 +00:00
|
|
|
default = self: super: { };
|
2020-01-26 10:26:33 +00:00
|
|
|
type = hm.types.overlayFunction;
|
2018-12-17 22:01:43 +00:00
|
|
|
defaultText = "self: super: {}";
|
|
|
|
example = literalExample ''
|
|
|
|
self: super: rec {
|
|
|
|
haskell-mode = self.melpaPackages.haskell-mode;
|
|
|
|
# ...
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Allows overriding packages within the Emacs package set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-11 19:23:11 +00:00
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
2019-01-03 01:15:17 +00:00
|
|
|
visible = false;
|
2018-09-11 19:23:11 +00:00
|
|
|
readOnly = true;
|
2019-01-03 01:15:17 +00:00
|
|
|
description = ''
|
|
|
|
The Emacs package including any overrides and extra packages.
|
|
|
|
'';
|
2018-09-11 19:23:11 +00:00
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-09-11 19:23:11 +00:00
|
|
|
home.packages = [ cfg.finalPackage ];
|
2021-01-29 16:43:49 +00:00
|
|
|
programs.emacs = {
|
|
|
|
finalPackage = emacsWithPackages cfg.extraPackages;
|
|
|
|
extraPackages = epkgs:
|
|
|
|
optional (cfg.extraConfig != "") (createConfPackage epkgs);
|
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
}
|