Commit 9c4af3cd7dca

Vincent Demeester <vincent@sbr.pm>
2020-06-01 11:52:07
users/vincent/dev: fix emacs-server modules…
… have a users/modules that can be shared by multiple users. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 8eef888
Changed files (5)
users/modules/services/default.nix
@@ -0,0 +1,5 @@
+{
+  imports = [
+    ./emacs-server.nix
+  ];
+}
users/modules/services/emacs-server.nix
@@ -0,0 +1,55 @@
+{ config, lib, pkgs, ... }:
+with lib;
+let
+  cfg = config.services.emacs-server;
+in
+{
+  options.services.emacs-server = {
+    enable = mkEnableOption "the Emacs daemon";
+    name = mkOption {
+      type = types.str;
+      description = "Name of the emacs server";
+      default = "default";
+    };
+    package = mkOption {
+      type = types.package;
+      description = "The Emacs package to use for running the daemon.";
+    };
+    shell = mkOption {
+      type = types.str;
+      description = "The shell used for starting Emacs.";
+    };
+    extraOptions = mkOption {
+      type = types.separatedString " ";
+      default = "";
+      description =
+        ''
+          The extra command-line options to pass to
+          <command>emacs</command> daemon.
+        '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    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 =
+          "${cfg.shell} 'exec ${cfg.package}/bin/emacs --fg-daemon=${cfg.name} ${cfg.extraOptions}'";
+        ExecStop = "${cfg.package}/bin/emacsclient --eval '(kill-emacs)'";
+        Restart = "on-failure";
+      };
+
+      Install = { WantedBy = [ "default.target" ]; };
+    };
+  };
+}
users/modules/default.nix
@@ -0,0 +1,5 @@
+{
+  imports = [
+    ./services
+  ];
+}
users/vincent/dev/go.nix
@@ -1,4 +1,4 @@
-{ pkgs, ... }:
+{ config, pkgs, ... }:
 
 {
   home.sessionVariables = {
users/vincent/default.nix
@@ -24,6 +24,7 @@ with lib;
 
   home-manager.users.vincent = lib.mkMerge (
     [
+      (import ../modules)
       (import ./core)
     ]
     ++ optionals config.profiles.dev.enable [