diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 5a9ed8bc..9f6bdb01 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -951,6 +951,21 @@ in A new module is available: 'programs.irssi'. ''; } + + { + time = "2019-02-09T14:09:58+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.emacs'. + + This module provides a user service that runs the Emacs + configured in + + programs.emacs + + as an Emacs daemon. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 4e3e6fe3..2fed3a9b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -87,6 +87,7 @@ let (loadModule ./services/blueman-applet.nix { }) (loadModule ./services/compton.nix { }) (loadModule ./services/dunst.nix { }) + (loadModule ./services/emacs.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/flameshot.nix { }) (loadModule ./services/gnome-keyring.nix { }) (loadModule ./services/gpg-agent.nix { }) diff --git a/modules/programs/emacs.nix b/modules/programs/emacs.nix index 12c7a5a9..a7f8b94c 100644 --- a/modules/programs/emacs.nix +++ b/modules/programs/emacs.nix @@ -66,7 +66,6 @@ in config = mkIf cfg.enable { home.packages = [ cfg.finalPackage ]; - programs.emacs.finalPackage = emacsWithPackages cfg.extraPackages; }; } diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix new file mode 100644 index 00000000..f33968c8 --- /dev/null +++ b/modules/services/emacs.nix @@ -0,0 +1,44 @@ +{ 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/"; + }; + + Service = { + ExecStart = "${pkgs.stdenv.shell} -l -c 'exec ${emacsBinPath}/emacs --fg-daemon'"; + ExecStop = "${emacsBinPath}/emacsclient --eval '(kill-emacs)'"; + Restart = "on-failure"; + }; + + Install = { + WantedBy = [ "default.target" ]; + }; + }; + }; +}