diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 9a5a27d7b..4c3675244 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -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; diff --git a/modules/services/sxhkd.nix b/modules/services/sxhkd.nix index f36cc9d66..031722a0f 100644 --- a/modules/services/sxhkd.nix +++ b/modules/services/sxhkd.nix @@ -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 PATH 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} & + ''; }; } diff --git a/tests/modules/services/sxhkd/service.nix b/tests/modules/services/sxhkd/service.nix index ee29b998a..2e26bb493 100644 --- a/tests/modules/services/sxhkd/service.nix +++ b/tests/modules/services/sxhkd/service.nix @@ -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} ''; }; }