Compare commits
No commits in common. "33e7d70192e9846c61407c81bdf0bf10437b49b1" and "cc173b20b9b7309d235be8e76668fbc3373f0212" have entirely different histories.
33e7d70192
...
cc173b20b9
2 changed files with 68 additions and 35 deletions
|
|
@ -1,24 +1,56 @@
|
|||
# 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;
|
||||
|
||||
# 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));
|
||||
# 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);
|
||||
|
||||
in {
|
||||
options.defaults = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,48 +1,49 @@
|
|||
{ ... }: {
|
||||
defaults."Taskbar" = {
|
||||
eula1Accepted = "true";
|
||||
sendCrashReports = "true";
|
||||
showMenubarIcon = "false";
|
||||
updatePolicy = "2";
|
||||
pinList = builtins.toJSON [
|
||||
centerTasksAndButtons = false;
|
||||
hideReviewOptions = true;
|
||||
permissionsResetOnce = true;
|
||||
pinList = [
|
||||
{
|
||||
bundleIdentifier = "com.apple.systempreferences";
|
||||
action = "launchOrActivateApp";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "com.apple.AppStore";
|
||||
action = "launchOrActivateApp";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "com.apple.finder";
|
||||
action = "finderNewWindow";
|
||||
bundleIdentifier = "com.apple.finder";
|
||||
}
|
||||
{
|
||||
action = "launchOrActivateApp";
|
||||
bundleIdentifier = "com.apple.AppStore";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "org.mozilla.firefox";
|
||||
action = "firefoxNewWindow";
|
||||
bundleIdentifier = "org.mozilla.firefox";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "org.mozilla.thunderbird";
|
||||
action = "launchOrActivateApp";
|
||||
bundleIdentifier = "com.apple.systempreferences";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "dev.zed.Zed";
|
||||
action = "launchOrActivateApp";
|
||||
}
|
||||
{
|
||||
bundleIdentifier = "com.electron.logseq";
|
||||
action = "launchOrActivateApp";
|
||||
}
|
||||
{
|
||||
action = "launchOrActivateApp";
|
||||
bundleIdentifier = "org.mozilla.thunderbird";
|
||||
}
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue