# User profile templates, applied on the booted image inside the logged-in # user's session through the guest agent (after generalize with autoLogon). # settings — { hideWidgets, wallpaper, dockApps, dockAutohide, showHiddenFiles } { pkgs, lib, ... }: let # Apple Events (osascript → System Events) need per-app automation consent that a # headless session cannot grant; desktoppr sets the wallpaper through NSWorkspace # inside the user's session instead (scriptingosx/desktoppr, pinned). desktoppr = pkgs.fetchurl { url = "https://github.com/scriptingosx/desktoppr/releases/download/v0.5/desktoppr-0.5-218.pkg"; hash = "sha256-HPtn1wI7xrx7HjyMz1yJGhutIodt938/vHfSeHfMe50="; }; in rec { settings = { hideWidgets ? true, # no desktop widgets (Sonoma+) wallpaper ? null, # image file (drv/path) set as the desktop picture dockApps ? null, # list of app paths, e.g. [ "/System/Applications/Utilities/Terminal.app" ]; null = untouched dockAutohide ? false, showHiddenFiles ? false, darkMode ? null, # true/false/null }: { name = "profile"; files = lib.optionals (wallpaper != null) [ { source = wallpaper; name = "wallpaper.${lib.last (lib.splitString "." (baseNameOf (toString wallpaper)))}"; } { source = desktoppr; name = "desktoppr.pkg"; } ]; bootScript = '' set -x [ -n "$CONSOLE_USER" ] || { echo "vmix: profile needs a logged-in user (generalize with autoLogon)"; exit 1; } H=$(dscl . -read "/Users/$CONSOLE_USER" NFSHomeDirectory | awk '{print $2}') D() { as_user defaults write "$@"; } ${lib.optionalString hideWidgets '' D com.apple.WindowManager StandardHideWidgets -int 1 D com.apple.WindowManager StageManagerHideWidgets -int 1 D com.apple.widgets widgetAppearance -int 0 ''} ${lib.optionalString (wallpaper != null) '' W="/Library/Desktop Pictures/vmix-wallpaper.${lib.last (lib.splitString "." (baseNameOf (toString wallpaper)))}" mkdir -p "/Library/Desktop Pictures"; cp "$V/wallpaper".* "$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 is written asynchronously; give it time before the shutdown sleep 15 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: '' D com.apple.dock persistent-apps -array-add "tile-typefile-tiletile-datafile-data_CFURLStringfile://${a}/_CFURLStringType15" '') dockApps} ''} ${lib.optionalString dockAutohide ''D com.apple.dock autohide -bool true''} ${lib.optionalString showHiddenFiles ''D com.apple.finder AppleShowAllFiles -bool true''} ${lib.optionalString (darkMode != null) (if darkMode then ''D -g AppleInterfaceStyle Dark'' else ''as_user defaults delete -g AppleInterfaceStyle 2>/dev/null || true'')} as_user killall Dock Finder WindowManager 2>/dev/null || true sleep 10 ''; }; }