Following on some of @billlevine’s suggestions:
The flox-build-examples repo he linked is a good resource to see how builds can be executed for various ecosystems, including Go and Rust.
In the Go example, we included three different variations on how to execute a build:
- quotes-app-go is an example of the default way to execute a manifest build
- quotes-app-go-pure is an example of how to build a Go application with the sandbox enabled (details) – the difference between this and the default build is that the application itself is built without network access, so the quotes-app-go-deps build is needed first to fetch and provide Go dependencies to the pure build in addition to those provided from the Flox environment
- quotes-app-go-nix is an example doing the same as the pure build, but using a Nix expression
Note that each of these examples describe a complete build on their own; any of the three methods are suitable for doing multi-platform builds.
Like @billlevine mentioned, the process for building on multiple platforms currently is to execute flox build on each one. Internally, we do this with GitHub Actions similar to:
build:
name: "Build"
strategy:
matrix:
os:
- "ubuntu-22.04"
- "ubuntu-22.04-arm"
- "macos-latest"
runs-on: "${{ matrix.os }}"
if: ${{ github.event_name != 'push' }}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 0
ref: "${{ github.head_ref }}"
- name: "Install flox"
uses: "flox/install-flox-action@main"
- name: "Build"
run: "flox build quotes-app-go"
Likewise, publishing can be done similarly:
publish:
name: "Publish"
strategy:
matrix:
os:
- "ubuntu-22.04"
- "ubuntu-22.04-arm"
- "macos-latest"
runs-on: "${{ matrix.os }}"
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 0
ref: "${{ github.head_ref }}"
- name: "Install flox"
uses: "flox/install-flox-action@main"
- name: "Build & Publish"
run: "flox publish quotes-app-go"
as @billlevine mentioned, you’ll need to have a FloxHub token available for this job for it to be able to publish.
Today, you can run flox auth token from the CLI to get a token. When using GitHub actions, we take that token and set it as a repository secret called FLOX_FLOXHUB_TOKEN which is automatically available to the job. In general, you’ll just need to make sure the token is available in the FLOX_FLOXHUB_TOKEN environment variable when flox publish is run.
One last note is that flox publish implicitly executes flox build first – to that end, we typically do flox build in PRs for testing, but only need to run flox publish on merges or release events as it always builds before executing the publish operation.
Hope this helps some – please let us know if you need additional detail or clarification.