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

nixos/espanso: add required capabilities for wayland #339594

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 31 additions & 11 deletions nixos/modules/services/desktops/espanso.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ in {
};
};

config = mkIf cfg.enable {
systemd.user.services.espanso = {
description = "Espanso daemon";
serviceConfig = {
ExecStart = "${lib.getExe cfg.package} daemon";
Restart = "on-failure";
};
wantedBy = [ "default.target" ];
};
config =
let
wayland = cfg.package == pkgs.espanso-wayland;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to do something like

Suggested change
wayland = cfg.package == pkgs.espanso-wayland;
wayland = builtins.elem "wayland" cfg.package.buildFeatures;

Otherwise this will probably not work if one pulls an espanso-wayland package from another nixpkgs branch (e.g., if one runs nixos-2405 but pulls espanso-wayland from nixpkgs-unstable).

in
mkMerge [
(mkIf cfg.enable {
systemd.user.services.espanso = {
description = "Espanso daemon";
serviceConfig = {
ExecStart =
# Espanso responsibly tries to drop capabilities as soon as possible
# but forks *after* dropping, leaving the `worker` process without the
# capabilities required for the EVDEV backend for wayland. Running
# `worker` directly from the wrapper works around this issue.
# https://github.com/NixOS/nixpkgs/issues/249364#issuecomment-2322837290
if wayland then "/run/wrappers/bin/espanso worker" else "${lib.getExe cfg.package} daemon";
Restart = "on-failure";
};
wantedBy = [ "default.target" ];
};

environment.systemPackages = [ cfg.package ];
};
environment.systemPackages = [ cfg.package ];
})
(mkIf wayland {
security.wrappers.espanso = {
source = "${lib.getExe cfg.package}";
capabilities = "cap_dac_override+p";
owner = "root";
group = "root";
};
})
];
}