Skip to content

Optimize NixOS-WSL #108

Optimize NixOS-WSL

Optimize NixOS-WSL #108

Workflow file for this run

name: Build and test flake devshells (using gh caches)
on:
push:
workflow_dispatch:
workflow_call:
inputs:
branch:
description: Branch name to build on
default: ""
required: false
type: string
secrets:
CACHIX_ACTIVATE_TOKEN:
CACHIX_AUTH_TOKEN:
required: true
jobs:
nix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
system:
- aarch64
- x86_64
shell:
- jdk21
- jvmlanguages-devenv --impure
- deno --impure
- flutter --impure
- ocaml --impure
- ruby
- rubyNix
- rubyShell
- rust --impure
- rustwasm32 --impure
- haskell --impure
- yaocaml
- rustyShell --impure
- python
- agda
- commonlisp
- playwright --impure
- playwright2 --impure
- ghcwasm
- haskell2 --impure
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Free Disk Space (Ubuntu)
if: contains(matrix.shell, 'ruby')
env:
_system: ${{ matrix.system }}-linux
uses: jlumbroso/free-disk-space@main
continue-on-error: true
with:
tool-cache: true
- name: Set Swap Space
uses: actionhippie/swap-space@master
with:
size: 20G
- name: Install qemu-user-static (aarch64)
if: matrix.system == 'aarch64'
env:
_system: ${{ matrix.system }}-linux
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sudo apt-get update --allow-releaseinfo-change
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Quick install
env:
_system: ${{ matrix.system }}-linux
uses: cachix/install-nix-action@v29
with:
install_url: 'https://releases.nixos.org/nix/nix-2.24.8/install'
extra_nix_config: |
substituters = https://cache.nixos.org/ https://nix-community.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
keep-going = true
show-trace = true
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
keep-outputs = true
${{ matrix.system == 'aarch64' && 'system = aarch64-linux # enables binfmt on that machine, see https://nixos.wiki/wiki/NixOS_on_ARM#Compiling_through_binfmt_QEMU' || '' }}
- name: Restore and cache Nix store
env:
_system: ${{ matrix.system }}-linux
uses: nix-community/cache-nix-action@v5
with:
# save a new cache every time ci file changes
primary-key: cache-${{ matrix.os }}-${{ hashFiles('.github/workflows/ci.yaml') }}
restore-prefixes-first-match: cache-${{ matrix.os }}-
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: cache-${{ matrix.os }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never
# and collect garbage in the Nix store until it reaches this size in bytes
gc-max-store-size: 8000000000
- name: Setup cachix
env:
_system: ${{ matrix.system }}-linux
uses: cachix/cachix-action@v15
with:
name: 573-bc
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Eval
env:
_system: ${{ matrix.system }}-linux
run: |
echo "::group::Eval command"
cachix use 573-bc
cachix use nix-on-droid
${{ (matrix.system == 'aarch64') && 'cachix watch-exec 573-bc -- \' || '' }}
nix eval .#devShells.$_system.${{ matrix.shell }} ${{ matrix.impure && '--impure' || '' }}
- name: Deploy cachix-agent spec
if: github.ref == 'refs/heads/wsl2' && matrix.deploy-agent
env:
CACHIX_ACTIVATE_TOKEN: ${{ secrets.CACHIX_ACTIVATE_TOKEN }}
TEST: ${{ matrix.system == 'aarch64' && '--impure' || '' }}
run: |
echo "::group::Build spec"
spec="$(nix build --print-out-paths ".#cachix-deploy-spec-${{ matrix.deploy-agent }}" ${{ (matrix.system == 'aarch64' || contains(matrix.nix-command, 'develop')) && '--impure' || '' }})"
echo "::group::Upload spec"
cachix push 573-bc "$spec"
# vim: set sw=2: