diff --git a/.github/actions/setup_bazel_nix/action.yml b/.github/actions/setup_bazel_nix/action.yml index 286ccf2e9d9..7b75030f09a 100644 --- a/.github/actions/setup_bazel_nix/action.yml +++ b/.github/actions/setup_bazel_nix/action.yml @@ -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 (e.g `['cowsay' 'ponysay']`). If empty, no tools will be installed." + default: "" + required: false runs: using: "composite" @@ -267,3 +271,42 @@ 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" + 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 + nix-build \ + --no-out-link \ + --arg tools "${tools}" \ + --argstr repository "${repository}" \ + --argstr rev "${gitSha}" \ + --attr tools \ + "${expressionFile}" + EXTRA_PATH=$(nix eval --raw --file "${expressionFile}" \ + --arg tools "${tools}" \ + --argstr repository "${repository}" \ + --argstr rev "${gitSha}" \ + pathVar) + echo "EXTRA_PATH=${EXTRA_PATH}" + echo "${EXTRA_PATH}" >> "${GITHUB_PATH}" + echo "::endgroup::"