@@ -233,7 +233,82 @@ There are three categories of options:
233233
234234# Troubleshooting
235235
236- ## Cannot launch applications
236+ ## Environment variables
237+
238+ ### systemd service
239+
240+ The xremap.service will only have access to environment variables defined
241+ through the ` Environment= ` and ` EnvironmentFile= ` entries in the service file.
242+ Moreover, other environment variables may be made available to the service by
243+ using ` systemctl [--user] set-environment VARIABLE=VALUE ` .
244+
245+ To expose ` home.sessionVariables ` to the service, the following may be done:
246+
247+ ``` nix
248+ {lib, pkgs, ...}:
249+ {
250+ # This will make every variable to have a `Environment=VARIABLE=VALUE` entry.
251+ systemd.user.services.xremap.Service = {
252+ Environment = lib.mapAttrsToList (n: v: "${n}=\"${builtins.toString v}\"") config.home.sessionVariables;
253+ };
254+ # This will make a single `EnvironmentFile` entry, but implies the build of
255+ # derivation.
256+ systemd.user.services.xremap.Service = {
257+ EnvironmentFile = builtins.toString (
258+ pkgs.writeText "xremap-session-vars-as-env-d" (
259+ builtins.concatStringsSep "\n" (
260+ lib.mapAttrsToList (n: v: "${n}=\"${builtins.toString v}\"") config.home.sessionVariables
261+ )
262+ )
263+ );
264+ };
265+ }
266+ ```
267+
268+ #### Session variables being overwritten by ` /etc/profile ` family of files on a shell
269+
270+ This happens because the session variables are set before the ` /etc/profile `
271+ files are sourced, which happens only the shell is spawned.
272+
273+ It can be fixed with the following if guard (following example uses Bash in a
274+ posix compliant manner, so it may be used on posix compliant shells, but needs
275+ adaptation for non compliant ones like fish):
276+
277+ ``` nix
278+ {config, lib, ...}: {
279+ programs.bash.initExtra = lib.mkOrder 99 ''
280+ if [ -z "$__HM_SESS_VARS_SOURCED" ]; then
281+ . ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh
282+ fi
283+ '';
284+ }
285+ ```
286+
287+ Now, the session variables will be sourced after the ones from ` /etc/profile ` .
288+
289+ ### Calling the binary directly as a non-root user
290+
291+ For xremap to have access to the user environment the following may be done:
292+
293+ 1 . If using home-manager for managing the xsession:
294+ ```nix
295+ {pkgs, ...}:
296+ {
297+ xsession.initExtra = ''
298+ ${lib.getExe pkgs.xremap} <path-to-config-file>
299+ '';
300+ }
301+ ```
302+ This exposes `home.sessionVariables` to xremap, since the `xsession` file
303+ sources the `xprofile` file, which sources the file with the session
304+ variables.
305+ 1 . If not using home-manager, DE/WM specific solutions may be used, that is, a
306+ way to launch xremap together with. Here are some non exhaustive solutions:
307+ 1 . dwm: add ` <binary> <config-file> & ` the autostart.sh script, if using the
308+ [autostart patch](https://dwm.suckless.org/patches/autostart/).
309+ 1 . Hyprland: hyprctl use ` hyprctl exec <binary> ` .
310+
311+ ### Cannot launch applications
237312
238313If there is a binding to launch an application that looks like this:
239314
0 commit comments