ci: allow jobs to install tools from pinned nixpkgs (#2605)

This commit is contained in:
Malte Poll 2023-11-16 14:41:34 +01:00 committed by GitHub
parent 183ce7a45a
commit ac8aac0e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,10 @@ inputs:
rbePlatform:
description: "RBE platform to use. If empty, RBE will not be used."
required: false
nixTools:
description: "Nix tools to install as list of strings separated by newlines. If empty, no tools will be installed."
default: ""
required: false
runs:
using: "composite"
@ -267,3 +271,47 @@ runs:
echo "common --disk_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
echo "common --repository_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
echo "::endgroup::"
- name: Install nix tools
if: inputs.nixTools != ''
shell: bash
env:
tools: ${{ inputs.nixTools }}
repository: ${{ github.repository }}
gitSha: ${{ github.sha }}
run: |
echo "::group::Install nix tools"
toolsNixList=$(printf ' "%s"' ${tools[@]})
toolsNixList="[ ${toolsNixList} ]"
expressionFile=$(mktemp)
cat << "EOF" > "${expressionFile}"
{ tools, repository, rev }:
let
repoFlake = builtins.getFlake ("github:" + repository + "/" + rev);
nixpkgs = repoFlake.inputs.nixpkgsUnstable;
pkgs = import nixpkgs { system = builtins.currentSystem; };
toolPkgs = map (p: pkgs.${p}) tools;
in
{
tools = pkgs.symlinkJoin { name = "tools"; paths = [ toolPkgs ]; };
pathVar = pkgs.lib.makeBinPath toolPkgs;
}
EOF
# ensure the store paths are created
nix-build \
--no-out-link \
--arg tools "${toolsNixList}" \
--argstr repository "${repository}" \
--argstr rev "${gitSha}" \
--attr tools \
"${expressionFile}"
# evaluate the path expression
# EXTRA_PATH=/nix/store/...:/nix/store/...:/nix/store/...
EXTRA_PATH=$(nix eval --raw --file "${expressionFile}" \
--arg tools "${toolsNixList}" \
--argstr repository "${repository}" \
--argstr rev "${gitSha}" \
pathVar)
echo "EXTRA_PATH=${EXTRA_PATH}"
echo "${EXTRA_PATH}" >> "${GITHUB_PATH}"
echo "::endgroup::"