Compare commits

...

3 commits

Author SHA1 Message Date
33e7d70192
fix (Taskbar.app): use strings for config values
For some reason, Taskbar.app stores all values as strings inside of it's
plist. Rework the config to account for that.
2025-11-03 10:31:31 -06:00
03e0863ec8
refactor (defaults): nix-darwin-like plist handling
A bug in Taskbar.app led to me switching out the defaults module for
something more like what nix-darwin has. Future testing leads me to
believe that the toPlist system was less of a problem, but this is more
robust anyway, so I'll keep it.
2025-11-03 10:29:31 -06:00
f973dd261f
fix (Taskbar.app): Update settings to post-reset 2025-11-02 23:06:29 -06:00
2 changed files with 38 additions and 71 deletions

View file

@ -1,56 +1,24 @@
# WARNING: This module was "vibe coded" by Claude Sonnet 4.5 Thinking
# Nix modules are mostly boilerplace, so the logic is (mostly) mine, and the
# rest comes from Claude. For reference, here was my prompt:
#
# I would like to write a new module for managing MacOS apps via the `defaults`
# cli. Ideally, the syntax that I want to include in my home-manager config
# should look like:
#
# ```nix
# darwin-defaults = {
# "com.fpfxtknjju.wbgcdolfev" = {
# centerTasksAndButtons = false;
# pinList = [
# { action = "finderNewWindow"; bundleIdentifier = "com.apple.finder"; }
# { action = "firefoxNewWindow"; bundleIdentifier = "org.mozilla.firefox"; }
# { action = "launchOrActivateApp"; bundleIdentifier = "com.electron.logseq"; }
# ];
# };
# "com.lwouis.alt-tab-macos" = {
# screenRecordingPermissionSkipped = true;
# nextWindowGesture = 1;
# };
# };
# ```
#
# This should be fairly easy to implement, as `defaults` accepts (escaped) plist
# strings, and Nix provides lib.generators.toPlist. Can you help me write the
# module, please?
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
inherit (pkgs.stdenv.hostPlatform) isDarwin; inherit (pkgs.stdenv.hostPlatform) isDarwin;
inherit (lib) mkOption types mkIf; inherit (lib) mkOption types mkIf;
inherit (lib.generators) toPlist; inherit (lib.generators) toPlist;
writeDefault = app: key: value:
"/usr/bin/defaults write -app ${app} '${key}' $'${
lib.strings.escape [ "'" ] (toPlist { escape = true; } value)
}'";
defaultsToList = domain: attrs:
lib.mapAttrsToList (writeDefault domain)
(lib.filterAttrs (n: v: v != null) attrs);
cfg = config.defaults; cfg = config.defaults;
# Convert domain settings to defaults import command # Generate all activation scripts by converting each domain's settings to defaults commands
domainToScript = domain: settings: activationScript = lib.concatStringsSep "\n" (lib.flatten
let (lib.mapAttrsToList (domain: settings: defaultsToList domain settings)
plistContent = toPlist { escape = true; } settings; cfg));
escapedDomain = lib.escapeShellArg domain;
in ''
$DRY_RUN_CMD echo "Applying defaults for ${domain}..."
$DRY_RUN_CMD /usr/bin/defaults import -app ${escapedDomain} - <<'EOF'
${plistContent}
EOF
$DRY_RUN_CMD killall ${escapedDomain} && open -a ${escapedDomain}
'';
# Generate all activation scripts
activationScript =
lib.concatStringsSep "\n" (lib.mapAttrsToList domainToScript cfg);
in { in {
options.defaults = mkOption { options.defaults = mkOption {

View file

@ -1,49 +1,48 @@
{ ... }: { { ... }: {
defaults."Taskbar" = { defaults."Taskbar" = {
centerTasksAndButtons = false; eula1Accepted = "true";
hideReviewOptions = true; sendCrashReports = "true";
permissionsResetOnce = true; showMenubarIcon = "false";
pinList = [ updatePolicy = "2";
pinList = builtins.toJSON [
{ {
action = "finderNewWindow";
bundleIdentifier = "com.apple.finder";
}
{
action = "launchOrActivateApp";
bundleIdentifier = "com.apple.AppStore";
}
{
action = "firefoxNewWindow";
bundleIdentifier = "org.mozilla.firefox";
}
{
action = "launchOrActivateApp";
bundleIdentifier = "com.apple.systempreferences"; bundleIdentifier = "com.apple.systempreferences";
action = "launchOrActivateApp";
} }
{ {
bundleIdentifier = "com.apple.AppStore";
action = "launchOrActivateApp"; action = "launchOrActivateApp";
bundleIdentifier = "com.electron.logseq";
} }
{ {
action = "launchOrActivateApp"; bundleIdentifier = "com.apple.finder";
action = "finderNewWindow";
}
{
bundleIdentifier = "org.mozilla.firefox";
action = "firefoxNewWindow";
}
{
bundleIdentifier = "org.mozilla.thunderbird"; bundleIdentifier = "org.mozilla.thunderbird";
action = "launchOrActivateApp";
} }
{ {
bundleIdentifier = "dev.zed.Zed";
action = "launchOrActivateApp"; action = "launchOrActivateApp";
}
{
bundleIdentifier = "com.electron.logseq";
action = "launchOrActivateApp";
}
{
bundleIdentifier = bundleIdentifier =
"com.apple.Safari.WebApp.2F51A6D0-087A-438F-92D3-A73FE09CB4CC"; "com.apple.Safari.WebApp.2F51A6D0-087A-438F-92D3-A73FE09CB4CC";
action = "launchOrActivateApp";
} }
{ {
action = "launchOrActivateApp";
bundleIdentifier = bundleIdentifier =
"com.apple.Safari.WebApp.5EC6478E-03A6-4147-8A4D-6EF3DE3F06D3"; "com.apple.Safari.WebApp.5EC6478E-03A6-4147-8A4D-6EF3DE3F06D3";
action = "launchOrActivateApp";
} }
]; ];
sendCrashReports = true;
showMenubarIcon = false;
showThumbnails = true;
showWindowTitleInThumbails = true;
taskViewMaxWidth = 200;
updatePolicy = 0;
}; };
} }