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";
|
2019-11-25 14:15:18 +01:00
|
|
|
# Adapted from upstream emacs.desktop
|
|
|
|
clientDesktopItem = pkgs.makeDesktopItem rec {
|
|
|
|
name = "emacsclient";
|
|
|
|
desktopName = "Emacs Client";
|
|
|
|
genericName = "Text Editor";
|
|
|
|
comment = "Edit text";
|
|
|
|
mimeType =
|
|
|
|
"text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;";
|
|
|
|
exec = "${emacsBinPath}/emacsclient ${
|
|
|
|
concatStringsSep " " cfg.client.arguments
|
|
|
|
} %F";
|
|
|
|
icon = "emacs";
|
|
|
|
type = "Application";
|
|
|
|
terminal = "false";
|
|
|
|
categories = "Utility;TextEditor;";
|
|
|
|
extraEntries = ''
|
|
|
|
StartupWMClass=Emacs
|
|
|
|
'';
|
|
|
|
};
|
2018-12-29 20:11:48 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2019-11-25 14:15:18 +01:00
|
|
|
options.services.emacs = {
|
|
|
|
enable = mkEnableOption "the Emacs daemon";
|
|
|
|
client = {
|
|
|
|
enable = mkEnableOption "generation of Emacs client desktop file";
|
|
|
|
arguments = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ "-c" ];
|
|
|
|
description = ''
|
|
|
|
Command-line arguments to pass to <command>emacsclient</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
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
|
|
|
};
|
2019-11-25 14:15:18 +01:00
|
|
|
|
|
|
|
home.packages = optional cfg.client.enable clientDesktopItem;
|
2018-12-29 20:11:48 +01:00
|
|
|
};
|
|
|
|
}
|