Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sxhkd: fix environment #1892

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 10 additions & 30 deletions modules/services/sxhkd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -57,44 +62,19 @@ in
i3-msg {workspace,move container to workspace} {1-10}
'';
};

extraPath = mkOption {
sumnerevans marked this conversation as resolved.
Show resolved Hide resolved
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} &
'';
};
}
23 changes: 16 additions & 7 deletions tests/modules/services/sxhkd/service.nix
Original file line number Diff line number Diff line change
@@ -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

assertFileExists $serviceFile
xsessionFile=home-files/.xsession

assertFileRegex $serviceFile 'ExecStart=@sxhkd@/bin/sxhkd -m 1'
assertFileExists $xsessionFile

assertFileRegex $serviceFile \
'Environment=PATH=.*\.nix-profile/bin:/home/the-user/bin:/extra/path/bin'
assertFileRegex $xsessionFile ${expectedFileRegex}
'';
};
}