<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<installer-gui-script minSpecVersion="1">
    <title>Flox</title>
    <license file="license.rtf" mime-type="text/rtf"/>
    <conclusion file="conclusion.html" mime-type="text/html"/>
    <background file="background.svg" mime-type="image/svg+xml" scaling="proportional" alignment="bottomleft"/>
    <background-darkAqua file="background-dark-aqua.svg" mime-type="image/svg+xml" scaling="proportional" alignment="bottomleft"/>
    <pkg-ref id="com.floxdev.flox">
        <bundle-version/>
    </pkg-ref>
    <options customize="always" allow-external-scripts="true" require-scripts="true" hostArchitectures="arm64"/>
    <choices-outline>
        <line choice="Flox"/>
        <line choice="flox.take.over"/>
    </choices-outline>
    <choice id="Flox" title="Flox" visible="!isTakeOver()" start_selected="!isTakeOver()">
        <pkg-ref id="com.floxdev.flox"/>
    </choice>
    <choice id="flox.take.over" title="Flox with Nix re-install" description="An existing Nix installation has been detected. NOTE: To install Flox using Nix, see https://flox.dev/docs/install-flox. Proceeding with this installer will: 1. Remove Nix and its dependency cacert from the default system profile. 2. Replace the Nix daemon with a Flox provided version. 3. Revert any changes the Nix installer made to shell rc files in /etc but backup the current files by adding a .backup-with-nix-before-flox suffix." visible="isTakeOver()" start_selected="false">
        <pkg-ref id="com.floxdev.flox"/>
    </choice>
    <pkg-ref id="com.floxdev.flox" version="1.11.2-9-ga862301b" onConclusion="none" installKBytes="51939" updateKBytes="0">#flox-1.11.2-9-ga862301b.pkg</pkg-ref>
    <installation-check script="installationCheck()"/>
    <script><![CDATA[
        function isTakeOver() {
            return system.files.fileExistsAtPath("/nix/var/nix/db/db.sqlite") && ! system.files.fileExistsAtPath("/etc/flox-version") && ! system.files.fileExistsAtPath("/etc/flox-version.update")
        }

        function isCorrectArchitecture() {
            let isArm = Boolean(system.sysctl("hw.optional.arm64"))
            return ((isArm && "arm64" == "arm64") || (!isArm && "arm64" == "x86_64"))
        }

        function installationCheck() {
            if (!isCorrectArchitecture()) {
                let brandString = system.sysctl("machdep.cpu.brand_string")
                my.result.type = "Fatal"
                my.result.title = "Installer Architecture Mismatch"
                my.result.message = `
                  Tried running the installer for architecture "arm64", but I'm a "${brandString}" machine.

                  Please download the correct installer and try again.
                `
                return false
            }
            return true
        }
        ]]></script>
    <product version="1.11.2-9-ga862301b"/>
</installer-gui-script>