Skip to content

Commit

Permalink
ci: allow jobs to install tools from pinned nixpkgs (#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 authored Nov 16, 2023
1 parent 183ce7a commit ac8aac0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/actions/setup_bazel_nix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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::"

0 comments on commit ac8aac0

Please sign in to comment.