Skip to content

feat(moonlight-qt-fork): init at 6.21.46 (#86) #46

feat(moonlight-qt-fork): init at 6.21.46 (#86)

feat(moonlight-qt-fork): init at 6.21.46 (#86) #46

name: Push to Cachix
on:
push:
branches: [main]
paths:
- 'pkgs/**'
- 'modules/flake/packages.nix'
- 'flake.nix'
- 'flake.lock'
- '.github/workflows/push-to-cachix.yml'
workflow_dispatch:
inputs:
skip:
description: 'Comma-separated packages to skip (added to CACHIX_SKIP)'
required: false
default: ''
permissions:
contents: read
env:
CACHIX_CACHE_NAME: tixpkgs
jobs:
detect:
name: Detect changed packages
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.packages_json }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Detect and filter packages
id: filter
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
SKIP_INPUT: ${{ inputs.skip }}
CACHIX_SKIP: ${{ vars.CACHIX_SKIP || '' }}
run: |
set -euo pipefail
# Gather skip list from repo variable and dispatch input
skip_list="${CACHIX_SKIP}"
if [ -n "${SKIP_INPUT:-}" ]; then
skip_list="${skip_list},${SKIP_INPUT}"
fi
skip_list="$(echo "$skip_list" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep -v '^$' | sort -u)"
# Get all known packages
mapfile -t all_packages < <(
nix eval .#packages.x86_64-linux \
--apply 'pkgs: builtins.attrNames pkgs' \
--json | jq -r '.[]' | sort -u
)
build_all=false
if [ "$EVENT_NAME" = "workflow_dispatch" ] || [[ -z "$BEFORE_SHA" || "$BEFORE_SHA" =~ ^0+$ ]]; then
build_all=true
elif git cat-file -e "$BEFORE_SHA^{commit}" && git cat-file -e "$CURRENT_SHA^{commit}"; then
git diff --name-only "$BEFORE_SHA" "$CURRENT_SHA" > changed-files.txt
else
build_all=true
fi
candidates=()
if [ "$build_all" = false ]; then
while IFS= read -r file; do
case "$file" in
flake.nix|flake.lock|modules/flake/packages.nix|.github/workflows/push-to-cachix.yml)
build_all=true
;;
pkgs/*)
IFS=/ read -r top bucket package rest <<< "$file"
if [ -n "${package:-}" ]; then
if [[ -z "${rest:-}" && "$package" == *.nix ]]; then
package="${package%.nix}"
fi
candidates+=("$package")
fi
;;
esac
done < changed-files.txt
fi
if [ "$build_all" = true ]; then
packages=("${all_packages[@]}")
else
printf '%s\n' "${all_packages[@]}" > all-packages.txt
printf '%s\n' "${candidates[@]}" | sort -u > candidate-packages.txt
mapfile -t packages < <(comm -12 candidate-packages.txt all-packages.txt)
fi
# Filter out skipped packages
if [ -n "$skip_list" ]; then
filtered=()
for pkg in "${packages[@]}"; do
if ! echo "$skip_list" | grep -Fxq "$pkg"; then
filtered+=("$pkg")
else
echo "Skipping $pkg (CACHIX_SKIP)"
fi
done
packages=("${filtered[@]}")
fi
packages_json="$(printf '%s\n' "${packages[@]}" | jq -Rsc 'split("\n") | map(select(length > 0))')"
echo "packages_json=${packages_json}" >> "$GITHUB_OUTPUT"
echo "Detected ${#packages[@]} package(s): ${packages[*]}"
build:
name: ${{ matrix.package }}
needs: detect
if: needs.detect.outputs.packages != '[]' && needs.detect.outputs.packages != ''
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.detect.outputs.packages) }}
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
with:
swap-storage: false
- name: Add build swap
run: |
set -euo pipefail
sudo fallocate -l 16G /mnt/nix-build-swapfile
sudo chmod 600 /mnt/nix-build-swapfile
sudo mkswap /mnt/nix-build-swapfile
sudo swapon /mnt/nix-build-swapfile
free -h
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v17
with:
name: ${{ env.CACHIX_CACHE_NAME }}
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
skipPush: true
- name: Build and push
env:
PACKAGE: ${{ matrix.package }}
CACHIX_CACHE_NAME: ${{ env.CACHIX_CACHE_NAME }}
run: |
set -euo pipefail
echo "::group::${PACKAGE}"
if build_json="$(nix build --print-build-logs --no-link --json ".#${PACKAGE}")"; then
mapfile -t output_paths < <(
jq -r '.[].outputs | to_entries[].value' <<< "$build_json" | sort -u
)
if [ "${#output_paths[@]}" -eq 0 ]; then
echo "Built ${PACKAGE}, but nix did not report any output paths."
exit 1
fi
echo "Built ${PACKAGE}; pushing package output path(s):"
printf ' %s\n' "${output_paths[@]}"
cachix push --omit-deriver "$CACHIX_CACHE_NAME" "${output_paths[@]}"
else
echo "Failed ${PACKAGE}"
exit 1
fi
echo "::endgroup::"