Created
December 29, 2018 13:01
-
-
Save Jomik/35786fa81ced8ee4209d752a57d57740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, config, pkgs, ... }: | |
with lib; | |
let | |
cfg = config.programs.emacs; | |
initEntry = types.submodule { | |
options = { | |
data = mkOption { | |
type = types.lines; | |
description = "Emacs code to execute"; | |
}; | |
before = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = "To be done before the given targets"; | |
}; | |
after = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = "To be done after the given targets"; | |
}; | |
}; | |
}; | |
modules = map (name: import "${./modules}/${name}" { inherit lib config pkgs; }) | |
(builtins.attrNames (builtins.readDir ./modules)); | |
in { | |
options.programs.emacs = mkMerge ((map (m: m.options) modules) ++ [ | |
{ | |
service = mkEnableOption "Emacs daemon systemd service"; | |
init = mkOption { | |
type = with types; attrsOf (coercedTo str dag.entryAnywhere initEntry); | |
default = dag.empty; | |
description = "Init entries"; | |
}; | |
} | |
]); | |
config = mkIf cfg.enable (mkMerge [ | |
{ | |
home.".emacs.d/init.el".text = | |
concatMapStringsSep | |
"\n\n" | |
({ name, data }: "; Section ${name}\n${data}") | |
(dagTopoSort cfg.init).result; | |
programs.emacs = mkMerge (map (m: m.config) modules) ++ [ | |
{ | |
init.pkgs = dag.entryAnywhere "(package-initialize)"; | |
} | |
]; | |
} | |
(mkIf cfg.service { | |
systemd.user.services.emacs = { | |
Unit = { | |
Description = "Emacs: the extensible, self-documenting text editor"; | |
Documentation = "info:emacs man:emacs(1) https://gnu.org/software/emacs/"; | |
}; | |
Service = { | |
Type = "simple"; | |
ExecStart = "${pkgs.stdenv.shell} -l -c 'exec ${cfg.finalPackage}/bin/emacs --fg-daemon'"; | |
ExecStop = "${cfg.finalPackage}/bin/emacsclient --eval '(kill-emacs)'"; | |
Restart = "on-failure"; | |
}; | |
Install = { | |
WantedBy = [ "default.target" ]; | |
}; | |
}; | |
})]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment