nix/darwin/sketchybar/default.nix
2025-04-07 02:23:57 -05:00

88 lines
2.3 KiB
Nix

{
pkgs,
lib,
config,
dots,
home-dir,
...
}:
let
cfg = config.custom.sketchybar;
sketchybar = lib.getExe pkgs.sketchybar;
lua = pkgs.lua5_4.withPackages (
ps: with ps; [
pkgs.custom.sbarlua
pkgs.custom.promise-lua
luafilesystem
]
);
in
{
options.custom = with lib; {
sketchybar = {
enable = mkEnableOption "Enable sketchybar";
logFile = mkOption {
type = types.str;
default = "${home-dir}/Library/Logs/sketchybar.log";
description = "Filepath of log output";
};
};
};
config = lib.mkIf cfg.enable {
services.sketchybar = {
enable = true;
extraPackages = with pkgs; [
custom.sk-utils
# sketchybar-app-font
];
};
hm.home.shellAliases = {
restart-sketchybar = ''launchctl kickstart -k gui/"$(id -u)"/org.nixos.sketchybar'';
};
hm.home.packages = with pkgs; [
sketchybar-app-font
];
hm.xdg.configFile = {
"sketchybar/sketchybarrc" = {
executable = true;
text = # Lua
''
#!${lua}/bin/lua
-- Add the sketchybar module to the package cpath (the module could be
-- installed into the default search path then this would not be needed)
package.path = "${dots}/darwin/sketchybar/config/?.lua;${dots}/darwin/sketchybar/config/?/?.lua;${dots}/darwin/sketchybar/config/?/init.lua;" .. package.path
sbar = require("sketchybar")
sbar.exec("killall sketchyhelper || sketchyhelper git.felix.sketchyhelper >/dev/null 2>&1 &")
sbar.begin_config()
require("init")
sbar.hotload(true)
sbar.end_config()
sbar.event_loop()
'';
};
};
services.aerospace.settings.exec-on-workspace-change = lib.mkIf config.custom.aerospace.enable [
"/bin/bash"
"-c"
"${sketchybar} --trigger aerospace_workspace_change FOCUSED_WORKSPACE=$AEROSPACE_FOCUSED_WORKSPACE PREV_WORKSPACE=$AEROSPACE_PREV_WORKSPACE"
];
launchd.user.agents.sketchybar.serviceConfig = {
StandardErrorPath = cfg.logFile;
StandardOutPath = cfg.logFile;
KeepAlive = lib.mkForce {
PathState = {
"/run/current-system/sw/bin/sketchybar" = true;
};
};
};
};
}