sketchybar: use finalpackage wrapper

Use finalPackage pattern with wrapper so that people who don't use the
service can benefit from the other options.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-05-21 22:36:24 -05:00
parent 5dc3bc3368
commit e4b0102f69
10 changed files with 295 additions and 238 deletions

View file

@ -1,5 +1,4 @@
{
# 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

View file

@ -2,22 +2,27 @@
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
package = config.lib.test.mkStubPackage {
name = "sketchybar";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/sketchybar
chmod 755 $out/bin/sketchybar
'';
};
# Test case for lua configuration without sbarLuaPackage
configType = "lua";
# sbarLuaPackage intentionally not set
sbarLuaPackage = null;
variables = {
PADDING = 3;
};
config.bar = {
height = 30;
};
config = ''
-- Basic lua config
local sbar = require("sbarlua")
sbar.bar:set({ height = 30 })
'';
};
test.asserts.assertions.expected = [
"When configType is set to \"lua\", sbarLuaPackage must be specified"
"When configType is set to \"lua\", service.sbarLuaPackage must be specified"
];
}

View file

@ -14,58 +14,54 @@ in
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
package = config.lib.test.mkStubPackage {
name = "sketchybar";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/sketchybar
chmod 755 $out/bin/sketchybar
'';
};
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 = ''
config = ''
-- This is a test Lua configuration
local sbar = require("sbarlua")
-- Configure bar
sbar.bar:set({
height = 30,
position = "top",
padding_left = 10,
padding_right = 10,
blur_radius = 20,
corner_radius = 9,
})
-- Configure defaults
sbar.defaults:set({
["icon.font"] = "SF Pro",
["icon.color"] = "0xff0000ff",
["background.height"] = 24,
["popup.background.border_width"] = 2,
["popup.background.corner_radius"] = 9,
})
-- Add items
sbar:add("item", "cpu", {
position = "right",
update_freq = 1,
script = "./scripts/cpu.lua"
script = "./scripts/cpu.lua",
})
-- Subscribe to events
sbar:subscribe("cpu", "system_woke")
'';
-- Update the bar
sbar:update()'';
};
# Validate the generated Lua configuration file

View file

@ -2,11 +2,6 @@
<!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>

View file

@ -9,7 +9,11 @@ let
self: super: {
sketchybar = config.lib.test.mkStubPackage {
name = "sketchybar";
outPath = "/@sketchybar@";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/sketchybar
chmod 755 $out/bin/sketchybar
'';
};
jq = config.lib.test.mkStubPackage { outPath = "/@jq@"; };
}
@ -21,23 +25,22 @@ in
package = hmPkgs.sketchybar;
configType = "bash";
variables = {
PADDING = "3";
FONT = "SF Pro";
COLOR = "0xff0000ff";
};
config = ''
#!/usr/bin/env bash
config.bar = {
height = 30;
position = "top";
padding_left = 10;
padding_right = 10;
};
# Configure bar
sketchybar --bar height=30 \
position=top \
padding_left=10 \
padding_right=10
# Update the bar
sketchybar --update
'';
# 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";
};

View file

@ -3,45 +3,42 @@
{
programs.sketchybar = {
enable = true;
package = config.lib.test.mkStubPackage { };
package = config.lib.test.mkStubPackage {
name = "sketchybar";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/sketchybar
chmod 755 $out/bin/sketchybar
'';
};
configType = "bash";
variables = {
PADDING = "3";
FONT = "SF Pro";
COLOR = "0xff0000ff";
};
config = ''
# Define colors
export COLOR_BLACK="0xff181926"
export COLOR_WHITE="0xffcad3f5"
config = {
bar = {
height = 30;
position = "top";
padding_left = 10;
padding_right = 10;
};
# Configure bar
sketchybar --bar height=32 \
position=top \
padding_left=10 \
padding_right=10 \
color=$COLOR_BLACK
defaults = {
"icon.font" = "$FONT";
"icon.color" = "$COLOR";
"background.height" = 24;
};
};
# Configure default values
sketchybar --default icon.font="SF Pro:Bold:14.0" \
icon.color=$COLOR_WHITE \
label.font="SF Pro:Bold:14.0" \
label.color=$COLOR_WHITE
plugins = [
{
name = "clock";
placement = "right";
script = "./scripts/clock.sh";
update_freq = 1;
}
];
# Add items to the bar
sketchybar --add item clock right \
--set clock script="date '+%H:%M'" \
update_freq=10
extraConfig = ''
# This is a test configuration
sketchybar --add item cpu right \
--set cpu script="$PLUGIN_DIR/cpu.sh" \
--subscribe cpu system_woke
# Update the bar
sketchybar --update
'';
};

View file

@ -1,26 +1,27 @@
export COLOR=0xff0000ff
export FONT=SF Pro
export PADDING=3
#!/usr/bin/env bash
# Generated by home-manager
# Define colors
export COLOR_BLACK="0xff181926"
export COLOR_WHITE="0xffcad3f5"
sketchybar --bar \
height=30 \
padding_left=10 \
padding_right=10 \
position=top
# Configure bar
sketchybar --bar height=32 \
position=top \
padding_left=10 \
padding_right=10 \
color=$COLOR_BLACK
sketchybar --default \
background.height=24 \
icon.color=$COLOR \
icon.font=$FONT
# Configure default values
sketchybar --default icon.font="SF Pro:Bold:14.0" \
icon.color=$COLOR_WHITE \
label.font="SF Pro:Bold:14.0" \
label.color=$COLOR_WHITE
# Add items to the bar
sketchybar --add item clock right \
--set clock script="date '+%H:%M'" \
update_freq=10
sketchybar --add item clock right --set clock script=./scripts/clock.sh update_freq=1
# Update the bar
sketchybar --update
# 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

@ -1,52 +1,36 @@
#!/usr/bin/env lua
-- Generated by home-manager
-- This is a test Lua configuration
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"
height = 30,
position = "top",
padding_left = 10,
padding_right = 10,
blur_radius = 20,
corner_radius = 9,
})
-- Configure defaults
sbar.defaults:set({
["icon.font"] = "SF Pro",
["icon.color"] = "0xff0000ff",
["background.height"] = 24,
["icon.color"] = "$COLOR",
["icon.font"] = "$FONT",
["label.padding"] = "$PADDING",
["popup.background.border_width"] = 2,
["popup.background.corner_radius"] = 9
["popup.background.corner_radius"] = 9,
})
-- Extra configuration
-- This is a test Lua configuration
-- Add items
sbar:add("item", "cpu", {
position = "right",
update_freq = 1,
script = "./scripts/cpu.lua"
script = "./scripts/cpu.lua",
})
-- Subscribe to events
sbar:subscribe("cpu", "system_woke")
-- Update the bar
sbar:update()