commit 9c4af3cd7dca62d263ce819c55a5fd061d393a91
parent 8eef888798e2fe182f43e272f223d13e403d6f7c
Author: Vincent Demeester <vincent@sbr.pm>
Date: Mon, 1 Jun 2020 11:52:07 +0200
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>
Diffstat:
5 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/users/modules/default.nix b/users/modules/default.nix
@@ -0,0 +1,5 @@
+{
+ imports = [
+ ./services
+ ];
+}
diff --git a/users/modules/services/default.nix b/users/modules/services/default.nix
@@ -0,0 +1,5 @@
+{
+ imports = [
+ ./emacs-server.nix
+ ];
+}
diff --git a/users/modules/services/emacs-server.nix b/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" ]; };
+ };
+ };
+}
diff --git a/users/vincent/default.nix b/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 [
diff --git a/users/vincent/dev/go.nix b/users/vincent/dev/go.nix
@@ -1,4 +1,4 @@
-{ pkgs, ... }:
+{ config, pkgs, ... }:
{
home.sessionVariables = {