aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Fisher <tadfisher@gmail.com>2020-06-23 17:17:33 -0700
committerRobert Helgesson <robert@rycee.net>2020-06-24 22:50:30 +0200
commit54b69d2ef868783533ce9c581cab7f0252b37149 (patch)
tree0842a082025f4e1f2f040f701edcc2c6584a7813
parent8f2342e13a2ddc84ed5053e2bfc393184258c686 (diff)
emacs: fix service environment
Emacs populates 'exec-path' at launch from the 'PATH' environment variable. Likewise, the emacs derivation from nixpkgs populates 'load-path' from the 'NIX_PROFILES' variable. As neither of these are available by default in the systemd user manager, revert to the previous behavior of launching the Emacs daemon from a login shell. Fixes #1354 Fixes #1340 PR #1355
-rw-r--r--modules/services/emacs.nix12
-rw-r--r--tests/modules/services/emacs/emacs-service-emacs.service2
-rw-r--r--tests/modules/services/emacs/emacs-service.nix7
-rw-r--r--tests/modules/services/emacs/emacs-socket-26-emacs.service2
-rw-r--r--tests/modules/services/emacs/emacs-socket-26.nix7
-rw-r--r--tests/modules/services/emacs/emacs-socket-27-emacs.service2
-rw-r--r--tests/modules/services/emacs/emacs-socket-27.nix7
7 files changed, 30 insertions, 9 deletions
diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix
index 70c8d0d7041..a73b750c513 100644
--- a/modules/services/emacs.nix
+++ b/modules/services/emacs.nix
@@ -97,13 +97,19 @@ in {
};
Service = {
- ExecStart = "${emacsBinPath}/emacs --fg-daemon${
+ # We wrap ExecStart in a login shell so Emacs starts with the user's
+ # environment, most importantly $PATH and $NIX_PROFILES. It may be
+ # worth investigating a more targeted approach for user services to
+ # import the user environment.
+ ExecStart = ''
+ ${pkgs.runtimeShell} -l -c "${emacsBinPath}/emacs --fg-daemon${
# In case the user sets 'server-directory' or 'server-name' in
# their Emacs config, we want to specify the socket path explicitly
# so launching 'emacs.service' manually doesn't break emacsclient
# when using socket activation.
- optionalString cfg.socketActivation.enable ''="${socketPath}"''
- }";
+ optionalString cfg.socketActivation.enable
+ "=${escapeShellArg socketPath}"
+ }"'';
# We use '(kill-emacs 0)' to avoid exiting with a failure code, which
# would restart the service immediately.
ExecStop = "${emacsBinPath}/emacsclient --eval '(kill-emacs 0)'";
diff --git a/tests/modules/services/emacs/emacs-service-emacs.service b/tests/modules/services/emacs/emacs-service-emacs.service
index c862e5688c6..d8a618a2671 100644
--- a/tests/modules/services/emacs/emacs-service-emacs.service
+++ b/tests/modules/services/emacs/emacs-service-emacs.service
@@ -2,7 +2,7 @@
WantedBy=default.target
[Service]
-ExecStart=@emacs@/bin/emacs --fg-daemon
+ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon"
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
Restart=on-failure
diff --git a/tests/modules/services/emacs/emacs-service.nix b/tests/modules/services/emacs/emacs-service.nix
index 06a26c82309..be27e9ab33d 100644
--- a/tests/modules/services/emacs/emacs-service.nix
+++ b/tests/modules/services/emacs/emacs-service.nix
@@ -24,7 +24,12 @@ with lib;
assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.service \
- ${./emacs-service-emacs.service}
+ ${
+ pkgs.substituteAll {
+ inherit (pkgs) runtimeShell;
+ src = ./emacs-service-emacs.service;
+ }
+ }
assertFileContent home-path/share/applications/emacsclient.desktop \
${./emacs-emacsclient.desktop}
'';
diff --git a/tests/modules/services/emacs/emacs-socket-26-emacs.service b/tests/modules/services/emacs/emacs-socket-26-emacs.service
index 8e9daba80d7..2d731c7ee1a 100644
--- a/tests/modules/services/emacs/emacs-socket-26-emacs.service
+++ b/tests/modules/services/emacs/emacs-socket-26-emacs.service
@@ -1,5 +1,5 @@
[Service]
-ExecStart=@emacs@/bin/emacs --fg-daemon="%T/emacs%U/server"
+ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%T/emacs%U/server'"
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
Restart=on-failure
diff --git a/tests/modules/services/emacs/emacs-socket-26.nix b/tests/modules/services/emacs/emacs-socket-26.nix
index 7905e19b346..65f06159e4c 100644
--- a/tests/modules/services/emacs/emacs-socket-26.nix
+++ b/tests/modules/services/emacs/emacs-socket-26.nix
@@ -27,7 +27,12 @@ with lib;
assertFileContent home-files/.config/systemd/user/emacs.socket \
${./emacs-socket-26-emacs.socket}
assertFileContent home-files/.config/systemd/user/emacs.service \
- ${./emacs-socket-26-emacs.service}
+ ${
+ pkgs.substituteAll {
+ inherit (pkgs) runtimeShell;
+ src = ./emacs-socket-26-emacs.service;
+ }
+ }
assertFileContent home-path/share/applications/emacsclient.desktop \
${./emacs-emacsclient.desktop}
'';
diff --git a/tests/modules/services/emacs/emacs-socket-27-emacs.service b/tests/modules/services/emacs/emacs-socket-27-emacs.service
index 99bacf2903b..408a5d24b5c 100644
--- a/tests/modules/services/emacs/emacs-socket-27-emacs.service
+++ b/tests/modules/services/emacs/emacs-socket-27-emacs.service
@@ -1,5 +1,5 @@
[Service]
-ExecStart=@emacs@/bin/emacs --fg-daemon="%t/emacs/server"
+ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%t/emacs/server'"
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
Restart=on-failure
diff --git a/tests/modules/services/emacs/emacs-socket-27.nix b/tests/modules/services/emacs/emacs-socket-27.nix
index d1ecb954a78..213dedca51c 100644
--- a/tests/modules/services/emacs/emacs-socket-27.nix
+++ b/tests/modules/services/emacs/emacs-socket-27.nix
@@ -29,7 +29,12 @@ in {
assertFileContent home-files/.config/systemd/user/emacs.socket \
${./emacs-socket-27-emacs.socket}
assertFileContent home-files/.config/systemd/user/emacs.service \
- ${./emacs-socket-27-emacs.service}
+ ${
+ pkgs.substituteAll {
+ inherit (pkgs) runtimeShell;
+ src = ./emacs-socket-27-emacs.service;
+ }
+ }
assertFileContent home-path/share/applications/emacsclient.desktop \
${./emacs-emacsclient.desktop}
'';