Skip to content

Commit 3d27a33

Browse files
committed
feat: optionally use remote builders
1 parent ca07769 commit 3d27a33

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

.github/actions/setup-nix/action.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ inputs:
1010
extra-nix-config:
1111
type: string
1212
default: ""
13+
builders:
14+
type: string
15+
default: ""
16+
ssh-key:
17+
type: string
18+
default: ""
19+
ssh-cert:
20+
type: string
21+
default: ""
1322

1423
runs:
1524
using: composite
@@ -46,13 +55,30 @@ runs:
4655
/Users/runner/Library/Developer/CoreSimulator \
4756
/Users/runner/hostedtoolcache &
4857
58+
- name: prepare remote builder config
59+
if: ${{ inputs.builders != '' && inputs.ssh-key != '' }}
60+
env:
61+
BUILDERS: ${{ inputs.builders }}
62+
SSH_KEY: ${{ inputs.ssh-key }}
63+
SSH_CERT: ${{ inputs.ssh-cert }}
64+
shell: bash
65+
run: |
66+
set -euo pipefail
67+
sudo mkdir -p /etc/nix/
68+
echo -e "$BUILDERS" | sudo tee /etc/nix/machines
69+
echo -e "$SSH_KEY" | sudo tee /etc/nix/ssh_id > /dev/null
70+
echo -e "$SSH_CERT" | sudo tee /etc/nix/ssh_id-cert.pub > /dev/null
71+
sudo chmod 400 /etc/nix/ssh_id{,-cert.pub}
72+
4973
- name: install nix
5074
uses: cachix/install-nix-action@v31
5175
with:
5276
# Putting build-dir in /nix is a workaround for https://github.com/wimpysworld/nothing-but-nix/issues/18
5377
extra_nix_config: |
5478
accept-flake-config = true
5579
build-dir = /nix/build
80+
builders = @/etc/nix/machines
81+
builders-use-substitutes = true
5682
sandbox = ${{ inputs.sandbox }}
5783
system = ${{ inputs.system }}
5884
${{ inputs.extra-nix-config }}

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ jobs:
8383
|| (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed'
8484
|| matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed'
8585
|| 'true' }}
86+
builders: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && vars.BUILDERS || '' }}
87+
ssh-key: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && secrets.SSH_KEY || '' }}
88+
ssh-cert: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && secrets.SSH_CERT || '' }}
8689

8790
- name: nix build
8891
run: nix build --keep-going -L ${{ inputs.packages }}

.github/workflows/review.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ jobs:
148148
|| (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed'
149149
|| matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed'
150150
|| 'true' }}
151+
builders: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && vars.BUILDERS || '' }}
152+
ssh-key: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && secrets.SSH_KEY || '' }}
153+
ssh-cert: ${{ (vars.USE_BUILDERS == 'yes' || vars.USE_BUILDERS == 'always') && secrets.SSH_CERT || '' }}
151154

152155
- name: install packages
153156
run: |
@@ -157,7 +160,7 @@ jobs:
157160
elif [[ ${{ inputs.push-to-cache && vars.CACHIX_CACHE != '' }} = true ]]; then
158161
pkgs+=(cachix)
159162
fi
160-
nix profile add "${pkgs[@]/#/.#}"
163+
nix profile add "${pkgs[@]/#/.#}" --builders ''
161164
162165
- name: clone nixpkgs
163166
uses: actions/checkout@v6
@@ -174,14 +177,15 @@ jobs:
174177
--no-exit-status \
175178
--no-headers \
176179
--print-result \
177-
--build-args="-L" \
180+
--build-args="-L $JOBS_ARG" \
178181
--pr-json="$PR_JSON" \
179182
$EXTRA_ARGS
180183
working-directory: nixpkgs
181184
env:
182185
GITHUB_TOKEN: ${{ github.token }}
183186
EXTRA_ARGS: ${{ inputs.extra-args }}
184187
PR_JSON: ${{ needs.prepare.outputs.pr }}
188+
JOBS_ARG: ${{ vars.USE_BUILDERS == 'always' && '-j0' || '' }}
185189

186190
- name: push results to cache
187191
if: ${{ inputs.push-to-cache && ((vars.ATTIC_SERVER != '' && vars.ATTIC_CACHE != '') || vars.CACHIX_CACHE != '') }}

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Run [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) in GitHub Actions
99
- Optionally start an [Upterm](https://upterm.dev/) session after nixpkgs-review has finished to allow interactive testing/debugging via SSH
1010
- Push new packages to an [Attic](https://github.com/zhaofengli/attic) or [Cachix](https://www.cachix.org/) cache
1111
- After a successful review, automatically mark the PR as ready for review, approve it, or merge it (directly or via the [nixpkgs-merge-bot](https://github.com/NixOS/nixpkgs-merge-bot))
12+
- Optionally use [Nix remote builders](https://nix.dev/manual/nix/latest/advanced-topics/distributed-builds) (either in addition to or instead of the local GitHub Actions runner).
1213
- Add a "Run nixpkgs-review" shortcut to pull request pages in nixpkgs
1314

1415
## Setup
@@ -52,6 +53,42 @@ extra-substituters = https://nix-community.cachix.org
5253
extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
5354
```
5455

56+
### Remote Builders (optional)
57+
It is possible to configure nixpkgs-review-gha to use [remote builders](https://nix.dev/manual/nix/latest/advanced-topics/distributed-builds) either instead of or in addition to the local GitHub Actions runner.
58+
For this to work, the GitHub Actions runner needs to be able to connect to your remote builders via SSH, and you need to configure an SSH keypair for authentication.
59+
60+
Set the following [secrets](../../settings/secrets/actions):
61+
62+
- `SSH_KEY`: A private ssh key which is authorized to access your remote builders. You can generate one using `ssh-keygen -t ed25519 -f ssh_key -N '' -C ''`.
63+
- `SSH_CERT`: If you have configured an [SSH certificate authority](https://manpages.debian.org/unstable/openssh-client/ssh-keygen.1.en.html#CERTIFICATES), the certificate which authorizes your `SSH_KEY` to access the remote builders. You don't need to set this variable if you have authorized your `SSH_KEY` directly (i.e. added your public key to `authorized_keys` on the remote builder).
64+
<details>
65+
<summary>Example command to generate a shortlived certificate:</summary>
66+
67+
```shell
68+
ssh-keygen -Us $CA_PUBKEY_PATH \
69+
-I nixpkgs-review-gha \
70+
-n $REMOTE_USERNAME \
71+
-O clear \
72+
-O force-command="nix-daemon --stdio" \
73+
-V +1h \
74+
$PUBKEY_PATH
75+
```
76+
77+
</details>
78+
79+
Set the following [variables](../../settings/variables/actions):
80+
81+
- `BUILDERS`: A newline separated list of build machines in the same format as the [`builders` option in `nix.conf`](https://nix.dev/manual/nix/latest/command-ref/conf-file#conf-builders). You will need to set the value of the third field (ssh identity) to `/etc/nix/ssh_id` which is where your `SSH_KEY` is placed. Your `SSH_CERT` should be picked up automatically, if you have configured one.
82+
- `USE_BUILDERS`: Either `no`, `yes`, or `always`. If set to `yes`, remote builders are used *in addition to* the GitHub Actions runner. If set to `always`, *only* remote builders are used and no builds happen on the runner. If set to `no`, remote builders are not used at all.
83+
84+
For example, you can set `BUILDERS` to the following if you want to build on the [nix-community builders](https://nix-community.org/community-builders/). Keep in mind that these builders should generally [not be trusted](https://nix-community.org/community-builders/#notes-on-security-and-safety), so be careful with what you might push into the [binary caches](#push-to-attic-cache-optional) you configured above.
85+
86+
```
87+
ssh-ng://YOUR_USERNAME@build-box.nix-community.org x86_64-linux /etc/nix/ssh_id 6 - benchmark,big-parallel,kvm,nixos-test,uid-range - c3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSUVsSVE1NHFBeTdEaDYzckJ1ZFlLZGJ6SkhycmJyck1YTFlsN1BrbWs4OEg=
88+
ssh-ng://YOUR_USERNAME@aarch64-build-box.nix-community.org aarch64-linux /etc/nix/ssh_id 20 - benchmark,big-parallel,gccarch-armv7-a,gccarch-armv8-a,kvm,nixos-test,uid-range - c3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSUc5dXlmaHlsaStCUnRrNjR5K25pcXRiK3NLcXVSR0daODdmNFlSYzhFRTE=
89+
ssh-ng://YOUR_USERNAME@darwin-build-box.nix-community.org x86_64-darwin,aarch64-darwin /etc/nix/ssh_id 2 - big-parallel - c3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSUtNSGhsY243ZlVwVXVpT0ZlSWhEcUJ6Qk5Gc2JOcXErTnB6dUdYM2U2enY=
90+
```
91+
5592
### Shortcuts on nixpkgs PR pages (optional)
5693
Add [`shortcut.user.js`](shortcut.user.js) as a userscript in your browser for `https://github.com/` for example using the [User JavaScript and CSS chrome extension](https://chromewebstore.google.com/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld) or [Violentmonkey](https://violentmonkey.github.io/).
5794

0 commit comments

Comments
 (0)