diff --git a/lib/images/macos/templates/profile/default.nix b/lib/images/macos/templates/profile/default.nix index fa663c2..80c44d1 100644 --- a/lib/images/macos/templates/profile/default.nix +++ b/lib/images/macos/templates/profile/default.nix @@ -35,19 +35,7 @@ rec { D com.apple.WindowManager StageManagerHideWidgets -int 1 D com.apple.widgets widgetAppearance -int 0 ''} - ${lib.optionalString (wallpaper != null) '' - # WallpaperAgent only keeps choices whose file lives in the user's own space - # ("No files include in the descriptor" for /Library/Desktop Pictures) - HP="$H/Pictures"; mkdir -p "$HP" - W="$HP/vmix-wallpaper.${lib.last (lib.splitString "." (baseNameOf (toString wallpaper)))}" - cp "$V/wallpaper".* "$W"; chown "$CONSOLE_USER" "$HP" "$W"; chmod 644 "$W" - installer -pkg "$V/desktoppr.pkg" -target / >/dev/null || echo "vmix: WARNING: desktoppr install failed" - as_user /usr/local/bin/desktoppr "$W" || echo "vmix: WARNING: could not set the wallpaper" - # the wallpaper store (~/Library/Application Support/com.apple.wallpaper) is - # written asynchronously by WallpaperAgent; give it time before the shutdown - sleep 30 - echo "vmix: wallpaper now: $(as_user /usr/local/bin/desktoppr 2>/dev/null)" - ''} + ${lib.optionalString (dockApps != null) '' D com.apple.dock persistent-apps -array ${lib.concatMapStringsSep "\n" (a: '' @@ -61,6 +49,28 @@ rec { else ''as_user defaults delete -g AppleInterfaceStyle 2>/dev/null || true'')} as_user killall Dock Finder WindowManager 2>/dev/null || true sleep 10 + # wallpaper last: WindowManager re-applies its desktop configuration when the + # widget/dock settings above change, which reverts a choice made before it + ${lib.optionalString (wallpaper != null) '' + # WallpaperAgent only keeps choices whose file lives in the user's own space + # ("No files include in the descriptor" for /Library/Desktop Pictures) + HP="$H/Pictures"; mkdir -p "$HP" + W="$HP/vmix-wallpaper.${lib.last (lib.splitString "." (baseNameOf (toString wallpaper)))}" + cp "$V/wallpaper".* "$W"; chown "$CONSOLE_USER" "$HP" "$W"; chmod 644 "$W" + installer -pkg "$V/desktoppr.pkg" -target / >/dev/null || echo "vmix: WARNING: desktoppr install failed" + # WallpaperAgent drops choices made while it is still initialising the + # session's store right after login: wait for the store, set, verify, retry + ST="$H/Library/Application Support/com.apple.wallpaper/Store/Index.plist" + for i in $(seq 1 60); do [ -f "$ST" ] && break; sleep 2; done; sleep 15 + for try in 1 2 3; do + as_user /usr/local/bin/desktoppr "$W" || echo "vmix: WARNING: could not set the wallpaper" + sleep 30 + CUR=$(as_user /usr/local/bin/desktoppr 2>/dev/null) + [ "$CUR" = "$W" ] && break + echo "vmix: wallpaper read-back says $CUR (lags behind the store), retrying" + done + echo "vmix: wallpaper read-back: $CUR (the store choice is what the next login uses)" + ''} ''; }; }