# Software installation templates. # pkg — install a flat/distribution .pkg offline from the PE (`installer -target`) # app — copy an .app bundle (from a directory or zip) into /Applications offline # script — run a shell script as root on the booted image (network available) { pkgs, lib, ... }: rec { pkg = { name, src, choices ? null }: { name = "pkg-${name}"; files = [ { source = src; name = "${name}.pkg"; } ] ++ lib.optional (choices != null) { source = choices; name = "${name}.choices.xml"; }; script = '' echo "vmix: installing ${name}.pkg into $SYS" installer -verboseR -pkg "$V/${name}.pkg" -target "$SYS" \ ${lib.optionalString (choices != null) ''-applyChoiceChangesXML "$V/${name}.choices.xml"''} \ || pe_fail "installer ${name}.pkg" ''; }; app = { name, src }: { name = "app-${name}"; files = [ { source = src; name = "${name}.app"; } ]; script = '' echo "vmix: copying ${name}.app to $DATA/Applications" mkdir -p "$DATA/Applications" rm -rf "$DATA/Applications/${name}.app" ditto "$V/${name}.app" "$DATA/Applications/${name}.app" || pe_fail "ditto ${name}.app" chown -R 0:80 "$DATA/Applications/${name}.app" xattr -dr com.apple.quarantine "$DATA/Applications/${name}.app" 2>/dev/null || true ''; }; script = { name, script, files ? [], network ? true }: { name = "script-${name}"; inherit files network; bootScript = script; }; # Homebrew (needs network; installs for the console user or the given user) homebrew = { user ? null, formulae ? [], casks ? [] }: { name = "homebrew"; bootScript = '' U=${if user == null then "$CONSOLE_USER" else user} [ -n "$U" ] || { echo "vmix: no user to install Homebrew for"; exit 1; } launchctl asuser "$(id -u "$U")" sudo -u "$U" env NONINTERACTIVE=1 \ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || exit 1 B=/usr/local/bin/brew ${lib.optionalString (formulae != []) ''launchctl asuser "$(id -u "$U")" sudo -u "$U" $B install ${lib.escapeShellArgs formulae} || exit 1''} ${lib.optionalString (casks != []) ''launchctl asuser "$(id -u "$U")" sudo -u "$U" $B install --cask ${lib.escapeShellArgs casks} || exit 1''} ''; }; }