Skip to content

Commit

Permalink
run: pull target from Nix cache with new input
Browse files Browse the repository at this point in the history
Pulling a single derivation and its deps from a Nix cache is a lot
faster than pulling the entire /nix/store produced by the discovery
phase, so allow us to skip the GitHub cache restoration if they are
available.
  • Loading branch information
nrdxp committed Dec 12, 2022
1 parent 97afc03 commit 29021fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions discover/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ outputs:
nix_conf:
description: "Nix configuration of the flake."
value: ${{ steps.eval.outputs.nix_conf }}
cached:
description: "Boolean marking whether results are cached in inputs.cache."
value: ${{ steps.eval.outputs.cached }}

runs:
using: "composite"
Expand Down
2 changes: 2 additions & 0 deletions discover/eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function cache() {
if [[ -n $drvs ]]; then
#shellcheck disable=SC2086
nix copy --derivation --to "$CACHE" $drvs

echo "cached=true" >> "$GITHUB_OUTPUT"
fi

echo "::endgroup::"
Expand Down
9 changes: 9 additions & 0 deletions run/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
json:
description: "JSON describing the action, found in the discovery phase."
required: true
cached:
description: "Boolean marking whether to pull discovery artifacts from the Nix cache."
required: false
extra_nix_config:
description: "Configuration to append to the nix.conf."
required: false
Expand All @@ -42,6 +45,7 @@ runs:
shell: bash

- name: Restore Cache & Discovery Results
if: inputs.cached != 'true' || inputs.cache == 'auto'
id: restore-cache
uses: divnix/[email protected]
with:
Expand All @@ -61,6 +65,11 @@ runs:
secret-key-files = ${{ env.NIX_KEY_PATH }}
${{ inputs.extra_nix_config }}
- name: Pull Target from Nix Cache
if: inputs.cached == 'true' && inputs.cache != 'auto'
run: nix copy --derivation --from ${{ inputs.cache }} ${{ fromJSON(env.JSON).targetDrv }}
shell: bash

- name: Build ${{ fromJSON(env.JSON).name }}
id: build
run: |
Expand Down

0 comments on commit 29021fc

Please sign in to comment.