2018-12-29 20:11:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.emacs;
|
|
|
|
emacsCfg = config.programs.emacs;
|
|
|
|
emacsBinPath = "${emacsCfg.finalPackage}/bin";
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
|
|
|
options.services.emacs = { enable = mkEnableOption "the Emacs daemon"; };
|
2018-12-29 20:11:48 +01:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-02-02 00:39:17 +01:00
|
|
|
assertions = [{
|
|
|
|
assertion = emacsCfg.enable;
|
|
|
|
message = "The Emacs service module requires"
|
|
|
|
+ " 'programs.emacs.enable = true'.";
|
|
|
|
}];
|
2018-12-29 20:11:48 +01:00
|
|
|
|
|
|
|
systemd.user.services.emacs = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Emacs: the extensible, self-documenting text editor";
|
2020-02-02 00:39:17 +01:00
|
|
|
Documentation =
|
|
|
|
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
2019-04-14 02:06:47 +02:00
|
|
|
|
|
|
|
# Avoid killing the Emacs session, which may be full of
|
|
|
|
# unsaved buffers.
|
|
|
|
X-RestartIfChanged = false;
|
2018-12-29 20:11:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
2020-02-02 00:39:17 +01:00
|
|
|
ExecStart =
|
|
|
|
"${pkgs.runtimeShell} -l -c 'exec ${emacsBinPath}/emacs --fg-daemon'";
|
2018-12-29 20:11:48 +01:00
|
|
|
ExecStop = "${emacsBinPath}/emacsclient --eval '(kill-emacs)'";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
2018-12-29 20:11:48 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|