home-manager/modules/services/emacs.nix

43 lines
1.1 KiB
Nix
Raw Normal View History

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