1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-02 13:03:33 +02:00

sxhkd: fix environment (#1892)

* sxhkd: move to xsession.initExtra

When sxhkd is launched as systemd service it
doesn't have $PATH a user expects to see.

* sxhkd: add news entry
This commit is contained in:
0qq 2021-05-07 22:28:52 +03:00 committed by GitHub
parent 86944b0fb1
commit ff959fd49a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 37 deletions

View File

@ -1954,6 +1954,18 @@ in
'';
}
{
time = "2021-05-02T11:22:42+00:00";
condition = hostPlatform.isLinux && config.services.sxhkd.enable;
message = ''
The sxhkd service now is started using 'xsession.initExtra',
therefore this module loses systemd service management capabilities
and works only if Home Manager starts the user X session.
The option 'services.sxhkd.extraPath' has been deprecated.
'';
}
{
time = "2021-05-06T20:47:37+00:00";
condition = hostPlatform.isLinux;

View File

@ -19,6 +19,11 @@ let
in
{
imports = [
(mkRemovedOptionModule ["services" "sxhkd" "extraPath"]
"This option is no longer needed and can be removed.")
];
options.services.sxhkd = {
enable = mkEnableOption "simple X hotkey daemon";
@ -57,44 +62,19 @@ in
i3-msg {workspace,move container to workspace} {1-10}
'';
};
extraPath = mkOption {
default = "";
type = types.envVar;
description = ''
Additional <envar>PATH</envar> entries to search for commands.
'';
example = "/home/some-user/bin:/extra/path/bin";
};
};
config = mkIf cfg.enable {
home.packages = [ pkgs.sxhkd ];
home.packages = [ cfg.package ];
xdg.configFile."sxhkd/sxhkdrc".text = concatStringsSep "\n" [
keybindingsStr
cfg.extraConfig
];
systemd.user.services.sxhkd = {
Unit = {
Description = "simple X hotkey daemon";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
Environment =
"PATH="
+ "${config.home.profileDirectory}/bin"
+ optionalString (cfg.extraPath != "") ":"
+ cfg.extraPath;
ExecStart = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}";
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
};
xsession.initExtra = ''
systemd-cat -t sxhkd systemd-run --user --scope -u sxhkd \
${cfg.package}/bin/sxhkd ${toString cfg.extraOptions} &
'';
};
}

View File

@ -1,22 +1,31 @@
{ config, pkgs, ... }:
let
expectedFileRegex = ''
systemd-cat -t sxhkd systemd-run --user --scope -u sxhkd \
@sxhkd@/bin/sxhkd -m 1 &
'';
in
{
config = {
xsession = {
enable = true;
windowManager.command = "";
};
services.sxhkd = {
enable = true;
package = pkgs.runCommandLocal "dummy-package" { } "mkdir $out" // { outPath = "@sxhkd@"; };
extraOptions = [ "-m 1" ];
extraPath = "/home/the-user/bin:/extra/path/bin";
};
nmt.script = ''
serviceFile=home-files/.config/systemd/user/sxhkd.service
xsessionFile=home-files/.xsession
assertFileExists $serviceFile
assertFileExists $xsessionFile
assertFileRegex $serviceFile 'ExecStart=@sxhkd@/bin/sxhkd -m 1'
assertFileRegex $serviceFile \
'Environment=PATH=.*\.nix-profile/bin:/home/the-user/bin:/extra/path/bin'
assertFileRegex $xsessionFile ${expectedFileRegex}
'';
};
}