Skip to content

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:

.github/workflow/ci.yml
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)!
  1. install-flox-action GitHub Action makes it easier to install flox in the CI.
  2. Once flox is installed you can run any flox 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:

.github/workflow/ci.yml
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)!
  1. install-flox-action GitHub Action makes it easier to install flox in the CI.

  2. A substituter is an additional store from which Nix will copy store objects it doesn't have.

    For details, see the supported store URIs.

  3. This is a secret key used to sign everything that is built.

    To generate your secret key use the nix key generate-secret command.

  4. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are needed when you are uploading to AWS S3.

  5. Once flox is installed you can run any flox command, eg. flox build, flox publish, ...

  6. This is the step that uploads binaries and will make your CI runs fast.

    $FLOX_SUBSTITUTER is the variable created by flox/install-flox-action and includes everything needed to work with flox 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.