Skip to content

Commit

Permalink
discover: allow result to be uploaded to Nix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Dec 12, 2022
1 parent b01efeb commit da2419a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions discover/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: "Standard Discovery"
description: "Find out what to build & run in a Standard project."

inputs:
cache:
description: "Nix cache to upload evaluation results to."
required: false
default: auto
github_pat:
description: "GitHub token for accessing private repos."
required: false
Expand Down Expand Up @@ -52,6 +56,7 @@ runs:
id: eval
env:
FLAKE: "github:${{ github.repository }}/${{ github.sha }}"
CACHE: ${{ inputs.cache }}
run: |
${{ github.action_path }}/eval.sh
shell: bash
26 changes: 23 additions & 3 deletions discover/eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

set -e

declare JSON
declare JSON result

function eval() {
echo "::group::Nix Evaluation"

local system delim

system="$(nix eval --raw --impure --expr 'builtins.currentSystem')"
JSON="$(nix eval "$FLAKE#__std.ci'.$system" --json | jq -c '
result=$(nix eval "$FLAKE#__std.ci'.$system" --json)
JSON="$(jq -c '
group_by(.block)
| map({
key: .[0].block,
Expand All @@ -23,7 +24,7 @@ function eval() {
| from_entries
)
})
| from_entries'
| from_entries' <<< "$result"
)"

nix_conf=("$(nix eval --raw "$FLAKE#__std.nixConfig")")
Expand All @@ -42,4 +43,23 @@ function eval() {
echo "::endgroup::"
}

function cache() {
echo "::group::Cache Evaluation"

local drvs

drvs=$(jq -r '.[]|select(.targetDrv != null)|.targetDrv' <<< "$result")

if [[ -n $drvs ]]; then
#shellcheck disable=SC2086
nix copy --derivation --to "$CACHE" $drvs
fi

echo "::endgroup::"
}

eval

if [[ $CACHE != 'auto' ]]; then
cache
fi

0 comments on commit da2419a

Please sign in to comment.