Skip to content

Commit

Permalink
CI: revive cachix
Browse files Browse the repository at this point in the history
  • Loading branch information
A1ca7raz committed Apr 24, 2024
1 parent 043417b commit a91371f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/push_cache.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env bash

# Variables
extra_args=${ATTIC_PUSH_ARGS:--j8}
cache=${ATTIC_CACHE:-test}
cache=${CACHIX_CACHE:-test}
retry_times=${ATTIC_PUSH_RETRY:-10}
arch=${ARCH:-x86_64-linux}
[[ $CI_MODE ]] && dryrun="" || dryrun=echo

# Functions
push_with_retry() {
for n in $(seq 1 ${retry_times}); do
$dryrun attic push ${extra_args} ${cache} $1 && return 0
echo $1 | $dryrun cachix push ${cache}
[[ $? == 0 ]] && return 0
done
false
}
Expand Down
63 changes: 63 additions & 0 deletions .github/push_cache_attic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# Variables
extra_args=${ATTIC_PUSH_ARGS:--j8}
cache=${ATTIC_CACHE:-test}
retry_times=${ATTIC_PUSH_RETRY:-10}
arch=${ARCH:-x86_64-linux}
[[ $CI_MODE ]] && dryrun="" || dryrun=echo

# Functions
push_with_retry() {
for n in $(seq 1 ${retry_times}); do
$dryrun attic push ${extra_args} ${cache} $1 && return 0
done
false
}

# Parse opts
pkgs=()
groups=()
for i in $*; do
if [[ $(nix eval --raw .#packageBundles.${arch}.${i}.type --impure 2> /dev/null) = "derivation" ]]; then
pkgs+=(${i})
else
groups+=(${i})
fi
done
# Calc store
pkglist=
if [[ $groups ]]; then
filter_expr="{ inherit (x) ${groups[@]}; }"
apply_expr="x: with builtins; let pkglist = ${filter_expr}; in map (x: map (y: y.outPath) (attrValues x)) (attrValues pkglist)"
pkglist+=($(nix eval .#packageBundles.${arch} --apply "$apply_expr" --impure | sed -e 's/"//g' -e 's/\[//g' -e 's/\]//g' -e 's/ /\n/g'))
fi
[[ $pkgs || $groups ]] && filter_expr="{ inherit (x) ${pkgs[@]}; }" || filter_expr="x"
apply_expr="x: with builtins; let pkglist = ${filter_expr}; in map (x: x.outPath) (attrValues pkglist)"
pkglist+=($(nix eval .#packages.${arch} --apply "$apply_expr" --impure | sed -e 's/"//g' -e 's/ /\n/g' | sed -e '1d' -e '$d'))
# Show package information
echo -en "\e[35m==>\e[0m Total \e[35m${#pkglist[*]}\e[0m package"
[[ ${#pkglist[*]} -gt 1 ]] && echo 's' || echo
[[ ${#pkglist[*]} == 0 ]] && echo -e "\e[31mERROR:\e[0m No package or wrong packages given." && exit 1
echo '>>>>>>>>>> Package Store >>>>>>>>>>'
for i in ${pkglist[*]}; do echo ${i}; done
echo '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
# Start push
fail=1
for i in ${pkglist[*]}; do
echo
echo -e " \e[32m=====>> $i\e[0m"
if push_with_retry $i; then
echo -en " \e[32m"
else
echo -en " \e[31m"; fail=;
fi
echo -e "<<=====\e[0m"
done
[[ $fail ]] && true || false
41 changes: 27 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ jobs:
env:
CI_MODE: 1
NIXPKGS_ALLOW_UNFREE: 1
ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
ATTIC_ACCESS_TOKEN: ${{ secrets.ATTIC_ACCESS_TOKEN }}
CACHIX_CACHE: ${{ secrets.CACHIX_CACHE }}
CACHIX_ACCESS_TOKEN: ${{ secrets.CACHIX_ACCESS_TOKEN }}
# ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
# ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
# ATTIC_ACCESS_TOKEN: ${{ secrets.ATTIC_ACCESS_TOKEN }}

steps:
- name: 0-1. Maximize space
Expand All @@ -68,17 +70,28 @@ jobs:
extra_nix_config: |
experimental-features = nix-command flakes repl-flake
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
substituters = https://cache.nixos.org/ https://cache.garnix.io
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=
- name: 0-4. Setup Attic
run: |
# curl -LO https://raw.githubusercontent.com/zhaofengli/attic/main/.github/install-attic-ci.sh
curl -LO https://raw.githubusercontent.com/icewind1991/attic-action/master/dist/main/install-attic-ci.sh
bash install-attic-ci.sh
- uses: 0.4. DeterminateSystems/magic-nix-cache-action@v2

- name: 0-5. Setup Cachix
uses: cachix/cachix-action@v14
with:
name: '${{ secrets.CACHIX_CACHE }}'
authToken: '${{ secrets.CACHIX_ACCESS_TOKEN }}'
skipPush: true

# https://github.com/zhaofengli/attic/blob/main/.github/workflows/build.yml#L30
export PATH=$HOME/.nix-profile/bin:$PATH
attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_ACCESS_TOKEN"
attic use "$ATTIC_CACHE"
# - name: 0-6. Setup Attic
# run: |
# # curl -LO https://raw.githubusercontent.com/zhaofengli/attic/main/.github/install-attic-ci.sh
# curl -LO https://raw.githubusercontent.com/icewind1991/attic-action/master/dist/main/install-attic-ci.sh
# bash install-attic-ci.sh
#
# # https://github.com/zhaofengli/attic/blob/main/.github/workflows/build.yml#L30
# export PATH=$HOME/.nix-profile/bin:$PATH
# attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_ACCESS_TOKEN"
# attic use "$ATTIC_CACHE"

- name: 1-1. Update package sources
if: ${{ inputs.update_source == true }}
Expand Down Expand Up @@ -114,6 +127,6 @@ jobs:
commit_message: "Update: sources"
file_pattern: "pkgs/_sources"

- name: 3-2. Push cache to Attic
- name: 3-2. Push cache to Cachix
if: ${{ inputs.push_cache == true }}
run: bash ./.github/push_cache.sh ${{ inputs.packages }}
run: bash ./.github/push_cache.sh ${{ inputs.packages }}
33 changes: 17 additions & 16 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
substituters = https://cache.nixos.org/ https://cache.garnix.io
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=
- name: 1-1. Update flake.lock
if: ${{ inputs.update_lock == true || github.event_name != 'workflow_dispatch' }}
Expand Down Expand Up @@ -88,19 +90,18 @@ jobs:
commit_message: "Update: flake.lock&sources"
file_pattern: "flake.lock pkgs/_sources"

# build_bundles:
# needs: bump_lock
# secrets: inherit
# permissions:
# contents: write
# strategy:
# matrix:
# bundles:
# - ciPackages
# - unfreePackages
# - JetBrainsPackages
# - uncategorized
# - authentikPackages
# uses: ./.github/workflows/build.yml
# with:
# packages: ${{ matrix.bundles }}
build_bundles:
needs: bump_lock
secrets: inherit
permissions:
contents: write
strategy:
matrix:
bundles:
- ciPackages
- unfreePackages
# - JetBrainsPackages
- uncategorized
uses: ./.github/workflows/build.yml
with:
packages: ${{ matrix.bundles }}

0 comments on commit a91371f

Please sign in to comment.