1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-17 00:29:45 +01:00
home-manager/modules/services/emacs.nix

76 lines
2.1 KiB
Nix
Raw Normal View History

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";
# 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 {
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/";
# 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
};
home.packages = optional cfg.client.enable clientDesktopItem;
2018-12-29 20:11:48 +01:00
};
}