fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Lin Jianemacs: add version for default.el package19c6a408

master
3.1 KiB105 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.emacs;
8
9  # Copied from all-packages.nix, with modifications to support
10  # overrides.
11  emacsPackages = let epkgs = pkgs.emacsPackagesFor cfg.package;
12  in epkgs.overrideScope' cfg.overrides;
13
14  emacsWithPackages = emacsPackages.emacsWithPackages;
15
16  extraPackages = epkgs:
17    let
18      packages = cfg.extraPackages epkgs;
19      userConfig = epkgs.trivialBuild {
20        pname = "default";
21        src = pkgs.writeText "default.el" cfg.extraConfig;
22        version = "0.1.0";
23        packageRequires = packages;
24      };
25    in packages ++ optional (cfg.extraConfig != "") userConfig;
26
27in {
28  meta.maintainers = [ maintainers.rycee ];
29
30  options = {
31    programs.emacs = {
32      enable = mkEnableOption "Emacs";
33
34      package = mkOption {
35        type = types.package;
36        default = pkgs.emacs;
37        defaultText = literalExpression "pkgs.emacs";
38        example = literalExpression "pkgs.emacs25-nox";
39        description = "The Emacs package to use.";
40      };
41
42      # NOTE: The config is placed in default.el instead of ~/.emacs.d so that
43      # it won't conflict with Emacs configuration frameworks. Users of these
44      # frameworks would still benefit from this option as it would easily allow
45      # them to have Nix-computed paths in their configuration.
46      extraConfig = mkOption {
47        type = types.lines;
48        default = "";
49        example = ''
50          (setq standard-indent 2)
51        '';
52        description = ''
53          Configuration to include in the Emacs default init file. See
54          <https://www.gnu.org/software/emacs/manual/html_node/elisp/Init-File.html>
55          for more.
56
57          Note, the `inhibit-startup-message` Emacs option
58          cannot be set here since Emacs disallows setting it from the default
59          initialization file.
60        '';
61      };
62
63      extraPackages = mkOption {
64        default = self: [ ];
65        type = hm.types.selectorFunction;
66        defaultText = "epkgs: []";
67        example = literalExpression "epkgs: [ epkgs.emms epkgs.magit ]";
68        description = ''
69          Extra packages available to Emacs. To get a list of
70          available packages run:
71          {command}`nix-env -f '<nixpkgs>' -qaP -A emacsPackages`.
72        '';
73      };
74
75      overrides = mkOption {
76        default = self: super: { };
77        type = hm.types.overlayFunction;
78        defaultText = "self: super: {}";
79        example = literalExpression ''
80          self: super: rec {
81            haskell-mode = self.melpaPackages.haskell-mode;
82            # ...
83          };
84        '';
85        description = ''
86          Allows overriding packages within the Emacs package set.
87        '';
88      };
89
90      finalPackage = mkOption {
91        type = types.package;
92        visible = false;
93        readOnly = true;
94        description = ''
95          The Emacs package including any overrides and extra packages.
96        '';
97      };
98    };
99  };
100
101  config = mkIf cfg.enable {
102    home.packages = [ cfg.finalPackage ];
103    programs.emacs.finalPackage = emacsWithPackages extraPackages;
104  };
105}