diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index 38267151..9a6ef5e4 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -81,6 +81,17 @@ in { enable = mkEnableOption "systemd socket activation for the Emacs service"; }; + startWithUserSession = lib.mkOption { + type = lib.types.bool; + default = !cfg.socketActivation.enable; + defaultText = + literalExpression "!config.services.emacs.socketActivation.enable"; + example = true; + description = '' + Whether to launch Emacs service with the systemd user session. + ''; + }; + defaultEditor = mkOption rec { type = types.bool; default = false; @@ -145,7 +156,7 @@ in { ExecStopPost = "${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}"; }; - } // optionalAttrs (!cfg.socketActivation.enable) { + } // optionalAttrs (cfg.startWithUserSession) { Install = { WantedBy = [ "default.target" ]; }; }; diff --git a/tests/modules/services/emacs/default.nix b/tests/modules/services/emacs/default.nix index 47493207..cbbd6f6a 100644 --- a/tests/modules/services/emacs/default.nix +++ b/tests/modules/services/emacs/default.nix @@ -4,4 +4,6 @@ emacs-socket-27 = ./emacs-socket-27.nix; emacs-socket-28 = ./emacs-socket-28.nix; emacs-default-editor = ./emacs-default-editor.nix; + emacs-socket-and-startWithUserSession = + ./emacs-socket-and-startWithUserSession.nix; } diff --git a/tests/modules/services/emacs/emacs-socket-and-startWithUserSession.nix b/tests/modules/services/emacs/emacs-socket-and-startWithUserSession.nix new file mode 100644 index 00000000..5f47089e --- /dev/null +++ b/tests/modules/services/emacs/emacs-socket-and-startWithUserSession.nix @@ -0,0 +1,27 @@ +{ lib, pkgs, ... }: + +with lib; + +{ + services.emacs = { + enable = true; + socketActivation.enable = true; + startWithUserSession = true; + }; + + nixpkgs.overlays = [ + (self: super: rec { + emacs = pkgs.writeShellScriptBin "dummy-emacs-28.0.5" "" // { + outPath = "@emacs@"; + }; + emacsPackagesFor = _: + makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); + }) + ]; + + nmt.script = '' + assertFileContains \ + home-files/.config/systemd/user/emacs.service \ + "WantedBy=default.target" + ''; +}