1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-31 04:04:45 +00:00
This commit is contained in:
Austin Horstman 2025-03-25 03:41:01 +05:00 committed by GitHub
commit 59619e85af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,39 +1,41 @@
{ config, lib, pkgs, ... }:
with lib;
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption types;
cfg = config.services.yabai;
toYabaiConfig = opts:
concatStringsSep "\n" (mapAttrsToList
(p: v: "yabai -m config ${p} ${toString v}")
opts);
toYabaiConfig =
opts:
lib.concatStringsSep "\n" (lib.mapAttrsToList (p: v: "yabai -m config ${p} ${toString v}") opts);
configFile = mkIf (cfg.config != { } || cfg.extraConfig != "")
"${pkgs.writeScript "yabairc" (
(if (cfg.config != {})
then "${toYabaiConfig cfg.config}"
else "")
+ optionalString (cfg.extraConfig != "") ("\n" + cfg.extraConfig + "\n"))}";
configFile =
lib.mkIf (cfg.config != { } || cfg.extraConfig != "")
"${pkgs.writeScript "yabairc" (
(if (cfg.config != { }) then "${toYabaiConfig cfg.config}" else "")
+ lib.optionalString (cfg.extraConfig != "") ("\n" + cfg.extraConfig + "\n")
)}";
in
{
options = with types; {
services.yabai.enable = mkOption {
type = bool;
options.services.yabai = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the yabai window manager.";
};
services.yabai.package = mkOption {
type = path;
package = mkOption {
type = types.path;
default = pkgs.yabai;
description = "The yabai package to use.";
};
services.yabai.enableScriptingAddition = mkOption {
type = bool;
enableScriptingAddition = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable yabai's scripting-addition.
@ -41,10 +43,10 @@ in
'';
};
services.yabai.config = mkOption {
type = attrs;
config = mkOption {
type = types.attrs;
default = { };
example = literalExpression ''
example = lib.literalExpression ''
{
focus_follows_mouse = "autoraise";
mouse_follows_focus = "off";
@ -62,41 +64,66 @@ in
'';
};
services.yabai.extraConfig = mkOption {
type = lines;
extraConfig = mkOption {
type = types.lines;
default = "";
example = literalExpression ''
example = lib.literalExpression ''
yabai -m rule --add app='System Preferences' manage=off
'';
description = "Extra arbitrary configuration to append to the configuration file";
};
errorLogFile = mkOption {
type = types.path;
default = "/tmp/yabai.err.log";
example = "/Users/khaneliman/Library/Logs/yabai.log";
description = "Path to the yabai error log file";
};
outLogFile = mkOption {
type = types.path;
default = "/tmp/yabai.out.log";
example = "/Users/khaneliman/Library/Logs/yabai.log";
description = "Path to the yabai stdout log file";
};
};
config = mkMerge [
(mkIf (cfg.enable) {
config = lib.mkMerge [
(lib.mkIf (cfg.enable) {
environment.systemPackages = [ cfg.package ];
launchd.user.agents.yabai = {
serviceConfig.ProgramArguments = [ "${cfg.package}/bin/yabai" ]
++ optionals (cfg.config != { } || cfg.extraConfig != "") [ "-c" configFile ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = true;
serviceConfig.EnvironmentVariables = {
PATH = "${cfg.package}/bin:${config.environment.systemPath}";
serviceConfig = {
ProgramArguments =
[ "${cfg.package}/bin/yabai" ]
++ lib.optionals (cfg.config != { } || cfg.extraConfig != "") [
"-c"
configFile
];
KeepAlive = true;
RunAtLoad = true;
EnvironmentVariables = {
PATH = "${cfg.package}/bin:${config.environment.systemPath}";
};
StandardOutPath = cfg.outLogFile;
StandardErrorPath = cfg.errorLogFile;
};
};
})
# TODO: [@cmacrae] Handle removal of yabai scripting additions
(mkIf (cfg.enableScriptingAddition) {
(lib.mkIf (cfg.enableScriptingAddition) {
launchd.daemons.yabai-sa = {
script = "${cfg.package}/bin/yabai --load-sa";
serviceConfig.RunAtLoad = true;
serviceConfig.KeepAlive.SuccessfulExit = false;
serviceConfig = {
RunAtLoad = true;
KeepAlive.SuccessfulExit = false;
StandardOutPath = "/var/log/yabai-sa.out.log";
StandardErrorPath = "/var/log/yabai-sa.err.log";
};
};
environment.etc."sudoers.d/yabai".source = pkgs.runCommand "sudoers-yabai" {} ''
environment.etc."sudoers.d/yabai".source = pkgs.runCommand "sudoers-yabai" { } ''
YABAI_BIN="${cfg.package}/bin/yabai"
SHASUM=$(sha256sum "$YABAI_BIN" | cut -d' ' -f1)
cat <<EOF >"$out"