Run flox with GitHub Actions¶
GitHub Actions makes it easy to automate your CI/CD workflow. Using
install-flox-action makes it easy for you to use flox
within those same GitHub Actions.
Build a flox package¶
Create a .github/workflows/ci.yml
file in your repo with the following contents:
name: "CI"
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install flox
uses: flox/install-flox-action@v1 # (1)!
- name: Build
run: flox build # (2)!
install-flox-action
GitHub Action makes it easier to installflox
in the CI.- Once
flox
is installed you can run anyflox
command, eg.flox build
,flox publish
, ...
Speed up your CI with caching¶
Waiting for CI to finish is never fun. So let's make it faster by adding a cache to out CI configuration.
Change .github/workflows/ci.yml
to look like this:
name: "CI"
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install flox
uses: flox/install-flox-action@v1 # (1)!
with:
substituter: s3://your-cache-here # (2)!
substituter-key: ${{ secrets.FLOX_STORE_PUBLIC_NIX_SECRET_KEY }} # (3)!
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # (4)!
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Build
run: flox build # (5)!
- name: Cache
run: flox nix copy --to "$FLOX_SUBSTITUTER" ./result # (6)!
-
install-flox-action
GitHub Action makes it easier to installflox
in the CI. -
A substituter is an additional store from which Nix will copy store objects it doesn't have.
For details, see the supported store URIs.
-
This is a secret key used to sign everything that is built.
To generate your secret key use the nix key generate-secret command.
-
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
are needed when you are uploading to AWS S3. -
Once
flox
is installed you can run anyflox
command, eg.flox build
,flox publish
, ... -
This is the step that uploads binaries and will make your CI runs fast.
$FLOX_SUBSTITUTER
is the variable created byflox/install-flox-action
and includes everything needed to work withflox nix copy
.Note
In the future this step is not going to be needed as we will automatically detect and upload everything that needs to be uploaded.