Skip to content

Commit 3d2bbae

Browse files
committed
ci: build VM artifacts with Nix
Refs #1683 Signed-off-by: Simon Scatton <[email protected]>
1 parent 516adcd commit 3d2bbae

4 files changed

Lines changed: 217 additions & 50 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Build Rust Binary
5+
description: Build, verify, package, and upload an auditable Rust binary
6+
7+
inputs:
8+
binary:
9+
description: Cargo binary name
10+
required: true
11+
triple:
12+
description: Rust target triple
13+
required: true
14+
dev-shell:
15+
description: Nix development shell used to build the binary
16+
required: true
17+
cargo-version:
18+
description: Cargo package version embedded in the binary
19+
required: true
20+
interpreter:
21+
description: ELF interpreter for a dynamically linked Linux binary
22+
required: false
23+
default: ""
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Cache Rust artifacts
29+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
30+
with:
31+
shared-key: binaries-${{ inputs.binary }}-${{ inputs.triple }}
32+
cache-on-failure: "true"
33+
cache-workspace-crates: "true"
34+
cache-bin: "false"
35+
cmd-format: nix develop ${{ inputs.dev-shell }} -c {0}
36+
37+
- name: Set version
38+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
39+
run: sed -i 's/^version = "0\.0\.0"$/version = "${{ inputs.cargo-version }}"/' Cargo.toml
40+
41+
- name: Build ${{ inputs.binary }}
42+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
43+
run: GIT_DIR=/nonexistent cargo auditable build --release --bin "${{ inputs.binary }}"
44+
45+
- name: Verify ${{ inputs.binary }}
46+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
47+
run: |
48+
# Confirm the binary runs and reports the expected name.
49+
target/release/${{ inputs.binary }} --version | grep -q '^${{ inputs.binary }} '
50+
# Confirm Syft can decode the embedded cargo-auditable metadata.
51+
SYFT_CHECK_FOR_APP_UPDATE=false syft file:target/release/${{ inputs.binary }} -o cyclonedx-json | grep 'pkg:cargo/' > /dev/null
52+
53+
- name: Verify static linkage
54+
if: endsWith(inputs.triple, '-linux-musl')
55+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
56+
run: tasks/scripts/verify-static-binary.sh target/release/${{ inputs.binary }}
57+
58+
- name: Normalize Linux dynamic binary
59+
if: endsWith(inputs.triple, '-linux-gnu')
60+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
61+
run: |
62+
binary=target/release/${{ inputs.binary }}
63+
# Remove Nix store paths so the binary can run on other distributions.
64+
patchelf --set-interpreter "${{ inputs.interpreter }}" --remove-rpath "$binary"
65+
# Z3 must be embedded instead of loaded from the target system.
66+
test -z "$(patchelf --print-needed "$binary" | grep '^libz3')"
67+
# Reject symbols introduced after glibc 2.28.
68+
tasks/scripts/verify-glibc-symbols.sh 2.28 "$binary"
69+
70+
- name: Package ${{ inputs.binary }}
71+
shell: nix develop ${{ inputs.dev-shell }} -c bash -euo pipefail {0}
72+
run: |
73+
install -Dm0755 target/release/${{ inputs.binary }} artifacts/${{ inputs.binary }}
74+
tar -czf artifacts/${{ inputs.binary }}-${{ inputs.triple }}.tar.gz -C artifacts ${{ inputs.binary }}
75+
76+
- name: Upload ${{ inputs.binary }}
77+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
78+
with:
79+
name: ${{ inputs.binary }}-${{ inputs.triple }}
80+
path: artifacts/*.tar.gz
81+
retention-days: 5
82+
if-no-files-found: error

‎.github/workflows/build-binaries.yml‎

Lines changed: 85 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
cargo="$(python3 tasks/scripts/release.py get-version --cargo)"
3939
echo "cargo=$cargo" >> "$GITHUB_OUTPUT"
4040
41-
binary:
41+
rust-binary:
4242
name: ${{ matrix.binary }} (${{ matrix.triple }})
4343
needs: version
4444
strategy:
@@ -56,6 +56,14 @@ jobs:
5656
triple: aarch64-apple-darwin
5757
runner: macos-15-xlarge
5858
dev_shell: .#devShells.aarch64-darwin.default
59+
- binary: openshell-sandbox
60+
triple: x86_64-unknown-linux-musl
61+
runner: linux-amd64-cpu8
62+
dev_shell: .#devShells.x86_64-linux.musl
63+
- binary: openshell-sandbox
64+
triple: aarch64-unknown-linux-musl
65+
runner: linux-arm64-cpu8
66+
dev_shell: .#devShells.aarch64-linux.musl
5967
- binary: openshell-gateway
6068
triple: x86_64-unknown-linux-gnu
6169
runner: linux-amd64-cpu8
@@ -72,70 +80,97 @@ jobs:
7280
dev_shell: .#devShells.aarch64-darwin.default
7381
runs-on: ${{ matrix.runner }}
7482
timeout-minutes: 60
75-
defaults:
76-
run:
77-
shell: nix develop ${{ matrix.dev_shell }} -c bash -euo pipefail {0}
7883
steps:
7984
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
8085
with:
8186
ref: ${{ inputs['checkout-ref'] || github.sha }}
8287

83-
- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
88+
- uses: ./.github/actions/setup-nix
8489
with:
85-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
90+
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
8691

87-
- uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17
92+
- name: Build ${{ matrix.binary }}
93+
uses: ./.github/actions/build-rust-binary
94+
with:
95+
binary: ${{ matrix.binary }}
96+
triple: ${{ matrix.triple }}
97+
dev-shell: ${{ matrix.dev_shell }}
98+
cargo-version: ${{ needs.version.outputs.cargo }}
99+
interpreter: ${{ matrix.interpreter }}
100+
101+
vm-driver:
102+
name: openshell-driver-vm (${{ matrix.triple }})
103+
needs: [version, rust-binary]
104+
strategy:
105+
matrix:
106+
include:
107+
- arch: x86_64
108+
triple: x86_64-unknown-linux-gnu
109+
runner: linux-amd64-cpu8
110+
dev_shell: .#devShells.x86_64-linux.glibc-2-28
111+
interpreter: /lib64/ld-linux-x86-64.so.2
112+
- arch: aarch64
113+
triple: aarch64-unknown-linux-gnu
114+
runner: linux-arm64-cpu8
115+
dev_shell: .#devShells.aarch64-linux.glibc-2-28
116+
interpreter: /lib/ld-linux-aarch64.so.1
117+
- arch: aarch64
118+
triple: aarch64-apple-darwin
119+
runner: macos-15-xlarge
120+
dev_shell: .#devShells.aarch64-darwin.default
121+
runs-on: ${{ matrix.runner }}
122+
timeout-minutes: 60
123+
defaults:
124+
run:
125+
shell: nix develop ${{ matrix.dev_shell }} -c bash -euo pipefail {0}
126+
steps:
127+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
88128
with:
89-
name: openshell
90-
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
129+
ref: ${{ inputs['checkout-ref'] || github.sha }}
91130

92-
- name: Cache Rust artifacts
93-
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
131+
- uses: ./.github/actions/setup-nix
94132
with:
95-
shared-key: binaries-${{ matrix.binary }}-${{ matrix.triple }}
96-
cache-on-failure: "true"
97-
cache-workspace-crates: "true"
98-
cache-bin: "false"
99-
cmd-format: nix develop ${{ matrix.dev_shell }} -c {0}
133+
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
100134

101-
- name: Set version
102-
run: sed -i 's/^version = "0\.0\.0"$/version = "${{ needs.version.outputs.cargo }}"/' Cargo.toml
135+
- name: Download openshell-sandbox
136+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
137+
with:
138+
name: openshell-sandbox-${{ matrix.arch }}-unknown-linux-musl
139+
path: sandbox
103140

104-
- name: Build ${{ matrix.binary }}
105-
run: GIT_DIR=/nonexistent cargo auditable build --release --bin "${{ matrix.binary }}"
141+
- name: Build VM runtime
142+
run: nix build .#vm-runtime
106143

107-
- name: Verify ${{ matrix.binary }}
144+
- name: Compress Linux VM runtime
145+
if: runner.os == 'Linux'
108146
run: |
109-
# Confirm the binary runs and reports the expected name.
110-
target/release/${{ matrix.binary }} --version | grep -q '^${{ matrix.binary }} '
111-
# Confirm Syft can decode the embedded cargo-auditable metadata.
112-
SYFT_CHECK_FOR_APP_UPDATE=false syft "file:target/release/${{ matrix.binary }}" -o cyclonedx-json | grep 'pkg:cargo/' > /dev/null
113-
114-
- name: Verify static linkage
115-
if: endsWith(matrix.triple, '-linux-musl')
116-
run: tasks/scripts/verify-static-binary.sh target/release/${{ matrix.binary }}
117-
118-
- name: Normalize Linux dynamic binary
119-
if: endsWith(matrix.triple, '-linux-gnu')
147+
install -d target/vm-runtime-compressed
148+
zstd -19 -T0 result/libkrun.so -o target/vm-runtime-compressed/libkrun.so.zst
149+
zstd -19 -T0 result/libkrunfw.so.5 -o target/vm-runtime-compressed/libkrunfw.so.5.zst
150+
zstd -19 -T0 result/gvproxy -o target/vm-runtime-compressed/gvproxy.zst
151+
zstd -19 -T0 result/umoci -o target/vm-runtime-compressed/umoci.zst
152+
153+
- name: Compress macOS VM runtime
154+
if: runner.os == 'macOS'
120155
run: |
121-
binary=target/release/${{ matrix.binary }}
122-
# Remove Nix store paths so the binary can run on other distributions.
123-
patchelf --set-interpreter "${{ matrix.interpreter }}" --remove-rpath "$binary"
124-
# Z3 must be embedded instead of loaded from the target system.
125-
test -z "$(patchelf --print-needed "$binary" | grep '^libz3')"
126-
# Reject symbols introduced after glibc 2.28.
127-
tasks/scripts/verify-glibc-symbols.sh 2.28 "$binary"
128-
129-
- name: Package ${{ matrix.binary }}
156+
install -d target/vm-runtime-compressed
157+
zstd -19 -T0 result/libkrun.dylib -o target/vm-runtime-compressed/libkrun.dylib.zst
158+
zstd -19 -T0 result/libkrunfw.5.dylib -o target/vm-runtime-compressed/libkrunfw.5.dylib.zst
159+
zstd -19 -T0 result/gvproxy -o target/vm-runtime-compressed/gvproxy.zst
160+
zstd -19 -T0 result/umoci -o target/vm-runtime-compressed/umoci.zst
161+
162+
- name: Add openshell-sandbox to VM runtime
130163
run: |
131-
mkdir -p artifacts
132-
install -m0755 target/release/${{ matrix.binary }} artifacts/${{ matrix.binary }}
133-
tar -czf artifacts/${{ matrix.binary }}-${{ matrix.triple }}.tar.gz -C artifacts ${{ matrix.binary }}
164+
tar -xzf sandbox/openshell-sandbox-${{ matrix.arch }}-unknown-linux-musl.tar.gz -C sandbox
165+
zstd -19 -T0 sandbox/openshell-sandbox -o target/vm-runtime-compressed/openshell-sandbox.zst
134166
135-
- name: Upload ${{ matrix.binary }}
136-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
167+
- name: Build openshell-driver-vm
168+
uses: ./.github/actions/build-rust-binary
169+
env:
170+
OPENSHELL_VM_RUNTIME_COMPRESSED_DIR: ${{ github.workspace }}/target/vm-runtime-compressed
137171
with:
138-
name: ${{ matrix.binary }}-${{ matrix.triple }}
139-
path: artifacts/*.tar.gz
140-
retention-days: 5
141-
if-no-files-found: error
172+
binary: openshell-driver-vm
173+
triple: ${{ matrix.triple }}
174+
dev-shell: ${{ matrix.dev_shell }}
175+
cargo-version: ${{ needs.version.outputs.cargo }}
176+
interpreter: ${{ matrix.interpreter }}

‎flake.nix‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
syft
6161
uv
6262
zizmor
63+
zstd
6364
];
6465
treefmtEval = treefmt-nix.lib.evalModule pkgs {
6566
projectRootFile = "flake.nix";
@@ -68,6 +69,7 @@
6869
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
6970
z3-static = pkgs.callPackage ./nix/pkgs/z3-static.nix { };
7071
aws-lc-static = pkgs.callPackage ./nix/pkgs/aws-lc-static.nix { };
72+
vmRuntime = pkgs.callPackage ./nix/pkgs/vm-runtime.nix { };
7173
testGuest = import ./nix/test-guest {
7274
inherit pkgs;
7375
qemuPkgs = testGuestPkgs;
@@ -78,6 +80,8 @@
7880
apps.test-guest = testGuest.app;
7981
apps.test-guest-cache = testGuest.cacheApp;
8082

83+
packages.vm-runtime = vmRuntime;
84+
8185
devShells = {
8286
default =
8387
(pkgs.mkShell.override {

‎nix/pkgs/vm-runtime.nix‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{
5+
fetchurl,
6+
stdenv,
7+
zstd,
8+
}:
9+
10+
let
11+
runtime =
12+
{
13+
x86_64-linux = {
14+
platform = "linux-x86_64";
15+
hash = "sha256-dw3Lc7IapCyNeE7j6dnlgd/b8Yc91/7IOi3XJORyILQ=";
16+
};
17+
aarch64-linux = {
18+
platform = "linux-aarch64";
19+
hash = "sha256-aJDuDb7AsuH9R+AyXA/JIxE9fJmZ5kP0Lkhg6F0Ot5A=";
20+
};
21+
aarch64-darwin = {
22+
platform = "darwin-aarch64";
23+
hash = "sha256-BDSeY5XGDozaBZzHTiQQX90jzsSc6shJZs5zdzludX0=";
24+
};
25+
}
26+
.${stdenv.hostPlatform.system};
27+
archive = fetchurl {
28+
url = "https://github.com/NVIDIA/OpenShell/releases/download/vm-runtime/vm-runtime-${runtime.platform}.tar.zst";
29+
inherit (runtime) hash;
30+
};
31+
in
32+
stdenv.mkDerivation {
33+
name = "openshell-vm-runtime-${runtime.platform}";
34+
35+
nativeBuildInputs = [ zstd ];
36+
dontUnpack = true;
37+
38+
installPhase = ''
39+
runHook preInstall
40+
41+
mkdir -p "$out"
42+
tar --extract --file ${archive} --directory "$out"
43+
44+
runHook postInstall
45+
'';
46+
}

0 commit comments

Comments
 (0)