mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +01:00
emacs: extend startWithUserSession to start after graphical session (#3010)
This commit is contained in:
parent
fa720861b5
commit
f714b17031
4 changed files with 75 additions and 6 deletions
|
@ -81,14 +81,14 @@ in {
|
|||
enable = mkEnableOption "systemd socket activation for the Emacs service";
|
||||
};
|
||||
|
||||
startWithUserSession = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
startWithUserSession = mkOption {
|
||||
type = with types; either bool (enum [ "graphical" ]);
|
||||
default = !cfg.socketActivation.enable;
|
||||
defaultText =
|
||||
literalExpression "!config.services.emacs.socketActivation.enable";
|
||||
example = true;
|
||||
example = "graphical";
|
||||
description = ''
|
||||
Whether to launch Emacs service with the systemd user session.
|
||||
Whether to launch Emacs service with the systemd user session. If it is <literal>true</literal>, Emacs service is started by default.target. If it is <literal>"graphical"</literal>, Emacs service is started by graphical-session.target.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -116,6 +116,11 @@ in {
|
|||
Documentation =
|
||||
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
||||
|
||||
After = optional (cfg.startWithUserSession == "graphical")
|
||||
"graphical-session.target";
|
||||
PartOf = optional (cfg.startWithUserSession == "graphical")
|
||||
"graphical-session.target";
|
||||
|
||||
# Avoid killing the Emacs session, which may be full of
|
||||
# unsaved buffers.
|
||||
X-RestartIfChanged = false;
|
||||
|
@ -156,8 +161,15 @@ in {
|
|||
ExecStopPost =
|
||||
"${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}";
|
||||
};
|
||||
} // optionalAttrs (cfg.startWithUserSession) {
|
||||
Install = { WantedBy = [ "default.target" ]; };
|
||||
} // optionalAttrs (cfg.startWithUserSession != false) {
|
||||
Install = {
|
||||
WantedBy = [
|
||||
(if cfg.startWithUserSession == true then
|
||||
"default.target"
|
||||
else
|
||||
"graphical-session.target")
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
home = {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
emacs-service-27 = ./emacs-service-27.nix;
|
||||
emacs-service-28 = ./emacs-service-28.nix;
|
||||
emacs-service-28-after-graphical-session-target =
|
||||
./emacs-service-28-after-graphical-session-target.nix;
|
||||
emacs-socket-27 = ./emacs-socket-27.nix;
|
||||
emacs-socket-28 = ./emacs-socket-28.nix;
|
||||
emacs-default-editor = ./emacs-default-editor.nix;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
config = {
|
||||
nixpkgs.overlays = [
|
||||
(self: super: rec {
|
||||
emacs = pkgs.writeShellScriptBin "dummy-emacs-28.2" "" // {
|
||||
outPath = "@emacs@";
|
||||
};
|
||||
emacsPackagesFor = _:
|
||||
makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
|
||||
})
|
||||
];
|
||||
|
||||
programs.emacs.enable = true;
|
||||
services.emacs.enable = true;
|
||||
services.emacs.client.enable = true;
|
||||
services.emacs.extraOptions = [ "-f" "exwm-enable" ];
|
||||
services.emacs.startWithUserSession = "graphical";
|
||||
|
||||
nmt.script = ''
|
||||
assertPathNotExists home-files/.config/systemd/user/emacs.socket
|
||||
assertFileExists home-files/.config/systemd/user/emacs.service
|
||||
assertFileExists home-path/share/applications/emacsclient.desktop
|
||||
|
||||
assertFileContent home-files/.config/systemd/user/emacs.service \
|
||||
${
|
||||
pkgs.substituteAll {
|
||||
inherit (pkgs) runtimeShell;
|
||||
src =
|
||||
./emacs-service-emacs-after-graphical-session-target.service;
|
||||
}
|
||||
}
|
||||
assertFileContent home-path/share/applications/emacsclient.desktop \
|
||||
${./emacs-28-emacsclient.desktop}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
[Install]
|
||||
WantedBy=graphical-session.target
|
||||
|
||||
[Service]
|
||||
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon '-f' 'exwm-enable'"
|
||||
Restart=on-failure
|
||||
SuccessExitStatus=15
|
||||
Type=notify
|
||||
|
||||
[Unit]
|
||||
After=graphical-session.target
|
||||
Description=Emacs text editor
|
||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
||||
PartOf=graphical-session.target
|
||||
X-RestartIfChanged=false
|
Loading…
Reference in a new issue