1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-13 20:30:02 +00:00

[yabai] Configure scripting addition

Allow admins to execute `yabai --load-sa` as the root user without
having to enter a password
This commit is contained in:
Richard Huang 2023-11-18 20:23:12 -08:00
parent e67f2bf515
commit 892482250c
No known key found for this signature in database
GPG key ID: FFDEF81D05C2EC94

View file

@ -7,9 +7,10 @@ let
toYabaiConfig = opts:
concatStringsSep "\n" (mapAttrsToList
(p: v: "yabai -m config ${p} ${toString v}") opts);
(p: v: "yabai -m config ${p} ${toString v}")
opts);
configFile = mkIf (cfg.config != {} || cfg.extraConfig != "")
configFile = mkIf (cfg.config != { } || cfg.extraConfig != "")
"${pkgs.writeScript "yabairc" (
(if (cfg.config != {})
then "${toYabaiConfig cfg.config}"
@ -42,7 +43,7 @@ in
services.yabai.config = mkOption {
type = attrs;
default = {};
default = { };
example = literalExpression ''
{
focus_follows_mouse = "autoraise";
@ -77,7 +78,7 @@ in
launchd.user.agents.yabai = {
serviceConfig.ProgramArguments = [ "${cfg.package}/bin/yabai" ]
++ optionals (cfg.config != {} || cfg.extraConfig != "") [ "-c" configFile ];
++ optionals (cfg.config != { } || cfg.extraConfig != "") [ "-c" configFile ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = true;
@ -101,6 +102,12 @@ in
serviceConfig.RunAtLoad = true;
serviceConfig.KeepAlive.SuccessfulExit = false;
};
environment.etc."sudoers.d/yabai".text =
let
sha = builtins.hashFile "sha256" "${cfg.package}/bin/yabai";
in
"%admin ALL=(root) NOPASSWD: sha256:${sha} ${cfg.package}/bin/yabai --load-sa";
})
];
}