From 9f396fddc61cb649b7989f3f51389c228bad13ff Mon Sep 17 00:00:00 2001 From: Hugo Geoffroy Date: Mon, 25 Nov 2019 14:15:18 +0100 Subject: [PATCH] emacs: add emacsclient desktop file Add an option to enable a .desktop file for the Emacs client. PR #1223 Co-authored-by: Michael Lingelbach Co-authored-by: Robert Helgesson --- modules/services/emacs.nix | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index 5b0e88db7..c02762625 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -7,9 +7,40 @@ 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 + ''; + }; in { - options.services.emacs = { enable = mkEnableOption "the Emacs daemon"; }; + 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 emacsclient. + ''; + }; + }; + }; config = mkIf cfg.enable { assertions = [{ @@ -38,5 +69,7 @@ in { Install = { WantedBy = [ "default.target" ]; }; }; + + home.packages = optional cfg.client.enable clientDesktopItem; }; }