sketchybar: add module

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2024-02-11 23:11:53 -06:00
parent c3d48a17aa
commit 5dc3bc3368
11 changed files with 519 additions and 0 deletions

View file

@ -0,0 +1,7 @@
{
# Combined tests with built-in validation
sketchybar = ./sketchybar.nix; # Bash configuration with validation
sketchybar-lua-config = ./sketchybar-lua-config.nix; # Lua configuration with validation
sketchybar-invalid-lua-config = ./sketchybar-invalid-lua-config.nix; # Tests error on missing sbarLua
sketchybar-service-integration = ./sketchybar-service-integration.nix; # Service integration with validation
}

View file

@ -0,0 +1,23 @@
{ config, ... }:
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
# Test case for lua configuration without sbarLuaPackage
configType = "lua";
# sbarLuaPackage intentionally not set
variables = {
PADDING = 3;
};
config.bar = {
height = 30;
};
};
test.asserts.assertions.expected = [
"When configType is set to \"lua\", sbarLuaPackage must be specified"
];
}

View file

@ -0,0 +1,77 @@
{ config, pkgs, ... }:
let
pkgsSbarlua = pkgs.writeTextFile {
name = "sbarlua";
destination = "/bin/sbarlua";
executable = true;
text = ''
#!/bin/sh
echo "SbarLua mock"
'';
};
in
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
configType = "lua";
sbarLuaPackage = pkgsSbarlua;
variables = {
PADDING = 3;
FONT = "SF Pro";
COLOR = "0xff0000ff";
# Test more complex values
ITEMS = [
"calendar"
"cpu"
"memory"
];
SETTINGS = {
refresh_freq = 1;
enable_logging = true;
};
};
config = {
bar = {
height = 30;
position = "top";
padding_left = 10;
padding_right = 10;
blur_radius = 20;
corner_radius = 9;
};
defaults = {
"icon.font" = "$FONT";
"icon.color" = "$COLOR";
"background.height" = 24;
"label.padding" = "$PADDING";
"popup.background.border_width" = 2;
"popup.background.corner_radius" = 9;
};
};
extraConfig = ''
-- This is a test Lua configuration
sbar:add("item", "cpu", {
position = "right",
update_freq = 1,
script = "./scripts/cpu.lua"
})
-- Subscribe to events
sbar:subscribe("cpu", "system_woke")
'';
};
# Validate the generated Lua configuration file
nmt.script = ''
assertFileContent \
home-files/.config/sketchybar/sketchybarrc \
${./sketchybarrc.lua}
'';
}

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/@sketchybar@/bin:/@jq@/bin</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.nix-community.home.sketchybar</string>
<key>ProcessType</key>
<string>Interactive</string>
<key>Program</key>
<string>/@sketchybar@/bin/sketchybar</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/home/hm-user/Library/Logs/sketchybar/sketchybar.err.log</string>
<key>StandardOutPath</key>
<string>/home/hm-user/Library/Logs/sketchybar/sketchybar.out.log</string>
</dict>
</plist>

View file

@ -0,0 +1,59 @@
{
config,
pkgs,
...
}:
let
hmPkgs = pkgs.extend (
self: super: {
sketchybar = config.lib.test.mkStubPackage {
name = "sketchybar";
outPath = "/@sketchybar@";
};
jq = config.lib.test.mkStubPackage { outPath = "/@jq@"; };
}
);
in
{
programs.sketchybar = {
enable = true;
package = hmPkgs.sketchybar;
configType = "bash";
variables = {
PADDING = "3";
FONT = "SF Pro";
COLOR = "0xff0000ff";
};
config.bar = {
height = 30;
position = "top";
padding_left = 10;
padding_right = 10;
};
# Enable the integrated service
service = {
enable = true;
extraPackages = [ hmPkgs.jq ];
errorLogFile = "/home/hm-user/Library/Logs/sketchybar/sketchybar.err.log";
outLogFile = "/home/hm-user/Library/Logs/sketchybar/sketchybar.out.log";
};
};
# Change home directory for the test
home.homeDirectory = "/home/hm-user";
# Validate the generated config files
nmt.script = ''
# Verify config file exists
assertFileExists home-files/.config/sketchybar/sketchybarrc
# Verify service file exists and matches expected content
serviceFile=LaunchAgents/org.nix-community.home.sketchybar.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./sketchybar-service-expected.plist}
'';
}

View file

@ -0,0 +1,53 @@
{ config, ... }:
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
configType = "bash";
variables = {
PADDING = "3";
FONT = "SF Pro";
COLOR = "0xff0000ff";
};
config = {
bar = {
height = 30;
position = "top";
padding_left = 10;
padding_right = 10;
};
defaults = {
"icon.font" = "$FONT";
"icon.color" = "$COLOR";
"background.height" = 24;
};
};
plugins = [
{
name = "clock";
placement = "right";
script = "./scripts/clock.sh";
update_freq = 1;
}
];
extraConfig = ''
# This is a test configuration
sketchybar --add item cpu right \
--set cpu script="$PLUGIN_DIR/cpu.sh" \
--subscribe cpu system_woke
'';
};
nmt.script = ''
assertFileContent \
home-files/.config/sketchybar/sketchybarrc \
${./sketchybarrc.bash}
'';
}

View file

@ -0,0 +1,26 @@
export COLOR=0xff0000ff
export FONT=SF Pro
export PADDING=3
sketchybar --bar \
height=30 \
padding_left=10 \
padding_right=10 \
position=top
sketchybar --default \
background.height=24 \
icon.color=$COLOR \
icon.font=$FONT
sketchybar --add item clock right --set clock script=./scripts/clock.sh update_freq=1
# This is a test configuration
sketchybar --add item cpu right \
--set cpu script="$PLUGIN_DIR/cpu.sh" \
--subscribe cpu system_woke
sketchybar --update

View file

@ -0,0 +1,52 @@
#!/usr/bin/env lua
-- Generated by home-manager
local sbar = require("sbarlua")
-- Set variables
sbar.variables["COLOR"] = "0xff0000ff"
sbar.variables["FONT"] = "SF Pro"
sbar.variables["ITEMS"] = {
"calendar",
"cpu",
"memory"
}
sbar.variables["PADDING"] = 3
sbar.variables["SETTINGS"] = {
["enable_logging"] = true,
["refresh_freq"] = 1
}
-- Configure bar
sbar.bar:set({
["blur_radius"] = 20,
["corner_radius"] = 9,
["height"] = 30,
["padding_left"] = 10,
["padding_right"] = 10,
["position"] = "top"
})
-- Configure defaults
sbar.defaults:set({
["background.height"] = 24,
["icon.color"] = "$COLOR",
["icon.font"] = "$FONT",
["label.padding"] = "$PADDING",
["popup.background.border_width"] = 2,
["popup.background.corner_radius"] = 9
})
-- Extra configuration
-- This is a test Lua configuration
sbar:add("item", "cpu", {
position = "right",
update_freq = 1,
script = "./scripts/cpu.lua"
})
-- Subscribe to events
sbar:subscribe("cpu", "system_woke")
-- Update the bar
sbar:update()