2020-10-12 00:22:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.emacs;
|
|
|
|
|
|
|
|
# Copied from all-packages.nix, with modifications to support
|
|
|
|
# overrides.
|
|
|
|
emacsPackages = let epkgs = pkgs.emacsPackagesFor cfg.package;
|
2024-06-04 18:23:39 +00:00
|
|
|
in epkgs.overrideScope cfg.overrides;
|
2020-10-12 00:22:58 +00:00
|
|
|
|
|
|
|
emacsWithPackages = emacsPackages.emacsWithPackages;
|
|
|
|
|
2023-01-10 09:35:00 +00:00
|
|
|
extraPackages = epkgs:
|
|
|
|
let
|
|
|
|
packages = cfg.extraPackages epkgs;
|
|
|
|
userConfig = epkgs.trivialBuild {
|
|
|
|
pname = "default";
|
|
|
|
src = pkgs.writeText "default.el" cfg.extraConfig;
|
2024-01-05 11:06:15 +00:00
|
|
|
version = "0.1.0";
|
2023-01-10 09:35:00 +00:00
|
|
|
packageRequires = packages;
|
|
|
|
};
|
|
|
|
in packages ++ optional (cfg.extraConfig != "") userConfig;
|
2021-11-04 16:42:44 +00:00
|
|
|
|
2020-10-12 00:22:58 +00:00
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.emacs = {
|
|
|
|
enable = mkEnableOption "Emacs";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.emacs;
|
2021-11-04 16:42:44 +00:00
|
|
|
defaultText = literalExpression "pkgs.emacs";
|
|
|
|
example = literalExpression "pkgs.emacs25-nox";
|
2020-10-12 00:22:58 +00:00
|
|
|
description = "The Emacs package to use.";
|
|
|
|
};
|
|
|
|
|
2021-11-04 16:42:44 +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
|
2023-08-08 10:19:01 +00:00
|
|
|
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Init-File.html>
|
2021-11-04 16:42:44 +00:00
|
|
|
for more.
|
2023-08-08 10:19:01 +00:00
|
|
|
|
|
|
|
Note, the `inhibit-startup-message` Emacs option
|
2023-01-10 09:35:00 +00:00
|
|
|
cannot be set here since Emacs disallows setting it from the default
|
|
|
|
initialization file.
|
2021-11-04 16:42:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-12 00:22:58 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
default = self: [ ];
|
|
|
|
type = hm.types.selectorFunction;
|
|
|
|
defaultText = "epkgs: []";
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression "epkgs: [ epkgs.emms epkgs.magit ]";
|
2020-10-12 00:22:58 +00:00
|
|
|
description = ''
|
|
|
|
Extra packages available to Emacs. To get a list of
|
|
|
|
available packages run:
|
2023-08-08 10:19:01 +00:00
|
|
|
{command}`nix-env -f '<nixpkgs>' -qaP -A emacsPackages`.
|
2020-10-12 00:22:58 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
overrides = mkOption {
|
|
|
|
default = self: super: { };
|
|
|
|
type = hm.types.overlayFunction;
|
|
|
|
defaultText = "self: super: {}";
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression ''
|
2020-10-12 00:22:58 +00:00
|
|
|
self: super: rec {
|
|
|
|
haskell-mode = self.melpaPackages.haskell-mode;
|
|
|
|
# ...
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Allows overriding packages within the Emacs package set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
The Emacs package including any overrides and extra packages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.finalPackage ];
|
2023-01-10 09:35:00 +00:00
|
|
|
programs.emacs.finalPackage = emacsWithPackages extraPackages;
|
2020-10-12 00:22:58 +00:00
|
|
|
};
|
|
|
|
}
|