Skip to content

flake: update

flake: update #409

name: Build large nix packages
on:
workflow_dispatch:
inputs:
branch:
description: "which branch to checkout"
required: false
type: string
update-nix-inputs:
description: "update nix inputs"
type: boolean
default: false
required: false
build-experimental-packages:
description: "build experimental packages"
type: boolean
default: true
required: false
workflow_call:
inputs:
branch:
description: "which branch to checkout"
required: false
type: string
update-nix-inputs:
description: "update nix inputs"
type: boolean
default: false
required: false
build-experimental-packages:
description: "build experimental packages"
type: boolean
default: true
required: false
pull_request:
branches:
- master
- main
- actions
- ci
- x86_64-linux
- aarch64-linux
- "releases/*"
paths:
- "*.nix"
- "**/*.nix"
- "nix/**"
- "flake.lock"
push:
branches:
- master
- main
- actions
- ci
- x86_64-linux
- aarch64-linux
- "releases/*"
paths:
- "*.nix"
- "**/*.nix"
- "nix/**"
- "flake.lock"
jobs:
build:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental || false }}
strategy:
fail-fast: false
matrix:
include:
- type: "expression"
# TODO: any better way to build overrided virtualbox derivation?
data: |
with (builtins.getFlake (builtins.toString ./.));
let
systemPackages = nixosConfigurations.maximal-x86_64-linux.config.environment.systemPackages;
packages = builtins.filter (p: builtins.match "virtualbox-.*" p.name != null) systemPackages;
package = builtins.elemAt packages 0;
in package
experimental: true
- type: "expression"
data: |
with (builtins.getFlake (builtins.toString ./.)); packages.x86_64-linux.dvm
experimental: true
- type: "nixosConfiguration"
data: "mdq"
experimental: true
free-disk-space: true
- type: "package"
data: "config.boot.kernelPackages.kernel"
experimental: false
- type: "package"
data: "pkgs.clojure-lsp"
experimental: false
- type: "package"
data: "pkgs.keepassxc"
experimental: false
- type: "package"
data: "pkgs.calibre"
experimental: false
- type: "package"
data: "pkgs.clash-verge"
experimental: false
- type: "package"
data: "pkgs.texlab"
experimental: false
- type: "package"
data: "pkgs.llvmPackages_latest.llvm"
experimental: false
- type: "package"
data: "pkgs.myPackages.emacs"
experimental: false
- type: "package"
data: "pkgs.myPackages.texLive"
experimental: false
- type: "arguments"
data: |
.#caddy
experimental: true
steps:
- name: Set up common variables
id: variables
env:
DATA: ${{ matrix.data }}
run: |
set -xeuo pipefail
set_output() {
for v in "$@"; do
echo "$v=${!v}" >> $GITHUB_OUTPUT
done
}
system=${{ matrix.system }}
system="${system:-x86_64-linux}"
freeDiskSpace=${{ matrix.free-disk-space }}
freeDiskSpace="${freeDiskSpace:-false}"
updateFlakeInputs=false
shouldSkip=false
case '${{ github.event_name }}' in
'push'|'pull_request')
# Always free disk space if this workflow is triggered by push or pull request.
# There is no harm in doing this as we don't expect this github actions workflow to finish soon in that case.
# And in some case (e.g. flake inputs is updated recently) freeing disk space is necessary.
freeDiskSpace="${freeDiskSpace:-true}"
if printf '%s\0' "x86_64-linux" "aarch64-linux" | grep -Fxz -- "${{ github.ref_name }}" && [[ "${{ github.ref_name }}" != "${system}" ]]; then
shouldSkip=true
fi
;;
# The shouldSkip and updateFlakeInputs logic below only applies to workflow_call/workflow_dispatch.
'workflow_call'|'workflow_dispatch')
if [[ "${{ format('{0}', !inputs.build-experimental-packages && matrix.experimental) }}" == 'true' ]]; then
shouldSkip=true
fi
if [[ "${{ format('{0}', inputs.update-nix-inputs) }} " == 'true' ]]; then
updateFlakeInputs=true
fi
;;
esac
nixExpressionBase64=
nixArguments=
case '${{ matrix.type }}' in
'expression')
nixExpressionBase64="$(base64 -w 0 <<< "$DATA")"
;;
'package')
nixExpressionBase64="$(base64 -w 0 <<< "with (builtins.getFlake (builtins.toString ./.)); nixosConfigurations.maximal-${system}.${{ matrix.data }}")"
;;
'nixosConfiguration')
nixExpressionBase64="$(base64 -w 0 <<< 'with (builtins.getFlake (builtins.toString ./.)); nixosConfigurations.${{ matrix.data }}.config.system.build.toplevel')"
;;
'arguments')
nixArguments="${{ matrix.data }}"
;;
*)
exit 1
;;
esac
set_output system freeDiskSpace shouldSkip updateFlakeInputs nixExpressionBase64 nixArguments
- name: Checkout repository
if: steps.variables.outputs.shouldSkip != 'true'
uses: actions/checkout@v4
with:
ref: "${{ inputs.branch || '' }}"
submodules: true
- name: Setup nix
if: steps.variables.outputs.shouldSkip != 'true'
uses: ./
with:
setup-cachix: true
cachix-auth-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
setup-qemu: true
free-disk-space: ${{ steps.variables.outputs.freeDiskSpace }}
nix-systems: "${{ steps.variables.outputs.system }}"
- name: Update nix flake inputs
if: steps.variables.outputs.updateFlakeInputs != 'true'
run: |
nix flake update
- name: Build the package
if: steps.variables.outputs.shouldSkip != 'true'
run: |
if [[ -n "${{ steps.variables.outputs.nixExpressionBase64 }}" ]]; then
base64 -d <<< "${{ steps.variables.outputs.nixExpressionBase64 }}" | tee temp.nix
nix build -f temp.nix
fi
if [[ -n "${{ steps.variables.outputs.nixArguments }}" ]]; then
nix build ${{ steps.variables.outputs.nixArguments }}
fi