aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/emacs.nix
diff options
context:
space:
mode:
Diffstat (limited to 'home-manager/modules/services/emacs.nix')
-rw-r--r--home-manager/modules/services/emacs.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/home-manager/modules/services/emacs.nix b/home-manager/modules/services/emacs.nix
new file mode 100644
index 00000000000..33d6871c61b
--- /dev/null
+++ b/home-manager/modules/services/emacs.nix
@@ -0,0 +1,48 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+ cfg = config.services.emacs;
+ emacsCfg = config.programs.emacs;
+ emacsBinPath = "${emacsCfg.finalPackage}/bin";
+
+in
+
+{
+ options.services.emacs = {
+ enable = mkEnableOption "the Emacs daemon";
+ };
+
+ config = mkIf cfg.enable {
+ assertions = [
+ {
+ assertion = emacsCfg.enable;
+ message = "The Emacs service module requires"
+ + " 'programs.emacs.enable = true'.";
+ }
+ ];
+
+ systemd.user.services.emacs = {
+ Unit = {
+ Description = "Emacs: the extensible, self-documenting text editor";
+ 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;
+ };
+
+ Service = {
+ ExecStart = "${pkgs.runtimeShell} -l -c 'exec ${emacsBinPath}/emacs --fg-daemon'";
+ ExecStop = "${emacsBinPath}/emacsclient --eval '(kill-emacs)'";
+ Restart = "on-failure";
+ };
+
+ Install = {
+ WantedBy = [ "default.target" ];
+ };
+ };
+ };
+}