diff --git a/modules/defaults.nix b/modules/defaults.nix index dd5b2d7..6bff1bb 100644 --- a/modules/defaults.nix +++ b/modules/defaults.nix @@ -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, ... }: let inherit (pkgs.stdenv.hostPlatform) isDarwin; inherit (lib) mkOption types mkIf; 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; - # Convert domain settings to defaults import command - domainToScript = domain: settings: - let - plistContent = toPlist { escape = true; } settings; - 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); + # Generate all activation scripts by converting each domain's settings to defaults commands + activationScript = lib.concatStringsSep "\n" (lib.flatten + (lib.mapAttrsToList (domain: settings: defaultsToList domain settings) + cfg)); in { options.defaults = mkOption { diff --git a/programs/taskbar.nix b/programs/taskbar.nix index 992c1f6..757d42d 100644 --- a/programs/taskbar.nix +++ b/programs/taskbar.nix @@ -1,49 +1,48 @@ { ... }: { defaults."Taskbar" = { - centerTasksAndButtons = false; - hideReviewOptions = true; - permissionsResetOnce = true; - pinList = [ + eula1Accepted = "true"; + sendCrashReports = "true"; + showMenubarIcon = "false"; + 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"; + action = "launchOrActivateApp"; } { + bundleIdentifier = "com.apple.AppStore"; action = "launchOrActivateApp"; - bundleIdentifier = "com.electron.logseq"; } { - action = "launchOrActivateApp"; + bundleIdentifier = "com.apple.finder"; + action = "finderNewWindow"; + } + { + bundleIdentifier = "org.mozilla.firefox"; + action = "firefoxNewWindow"; + } + { bundleIdentifier = "org.mozilla.thunderbird"; + action = "launchOrActivateApp"; } { + bundleIdentifier = "dev.zed.Zed"; action = "launchOrActivateApp"; + } + { + bundleIdentifier = "com.electron.logseq"; + action = "launchOrActivateApp"; + } + { bundleIdentifier = "com.apple.Safari.WebApp.2F51A6D0-087A-438F-92D3-A73FE09CB4CC"; + action = "launchOrActivateApp"; } { - action = "launchOrActivateApp"; bundleIdentifier = "com.apple.Safari.WebApp.5EC6478E-03A6-4147-8A4D-6EF3DE3F06D3"; + action = "launchOrActivateApp"; } ]; - sendCrashReports = true; - showMenubarIcon = false; - showThumbnails = true; - showWindowTitleInThumbails = true; - taskViewMaxWidth = 200; - updatePolicy = 0; }; }