Skip to content

Commit a9f81b1

Browse files
checkpoint
1 parent 99d08f1 commit a9f81b1

File tree

4 files changed

+127
-5
lines changed

4 files changed

+127
-5
lines changed

flowey/flowey_lib_common/src/nix_deps_provider.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ flowey_request! {
2222
GetOpenvmmDeps(OpenvmmDepsArch, WriteVar<PathBuf>),
2323
/// Get the Nix store path for protoc
2424
GetProtoc(WriteVar<PathBuf>),
25+
/// Get the Nix store path for openhcl_kernel package root
26+
GetOpenhclKernelPackage(WriteVar<PathBuf>),
27+
/// Get the Nix store path for UEFI firmware (MSVM.fd)
28+
GetUefiMuMsvm(WriteVar<PathBuf>),
2529
}
2630
}
2731

@@ -38,6 +42,9 @@ impl FlowNode for Node {
3842
let mut openvmm_deps_requests: BTreeMap<OpenvmmDepsArch, Vec<WriteVar<PathBuf>>> =
3943
BTreeMap::new();
4044
let mut protoc_requests = Vec::new();
45+
let mut openhcl_kernel_vmlinux_requests = Vec::new();
46+
let mut openhcl_kernel_modules_requests = Vec::new();
47+
let mut uefi_mu_msvm_requests = Vec::new();
4148

4249
// Parse all requests and group by type
4350
for req in requests {
@@ -46,17 +53,28 @@ impl FlowNode for Node {
4653
openvmm_deps_requests.entry(arch).or_default().push(var);
4754
}
4855
Request::GetProtoc(var) => protoc_requests.push(var),
56+
Request::GetOpenhclKernelVmlinux(var) => openhcl_kernel_vmlinux_requests.push(var),
57+
Request::GetOpenhclKernelModules(var) => openhcl_kernel_modules_requests.push(var),
58+
Request::GetUefiMuMsvm(var) => uefi_mu_msvm_requests.push(var),
4959
}
5060
}
5161

5262
// Only emit step if there are actual requests
53-
if openvmm_deps_requests.is_empty() && protoc_requests.is_empty() {
63+
if openvmm_deps_requests.is_empty()
64+
&& protoc_requests.is_empty()
65+
&& openhcl_kernel_vmlinux_requests.is_empty()
66+
&& openhcl_kernel_modules_requests.is_empty()
67+
&& uefi_mu_msvm_requests.is_empty()
68+
{
5469
return Ok(());
5570
}
5671

5772
ctx.emit_rust_step("resolve nix dependency paths", |ctx| {
5873
let openvmm_deps_requests = openvmm_deps_requests.claim(ctx);
5974
let protoc_requests = protoc_requests.claim(ctx);
75+
let openhcl_kernel_vmlinux_requests = openhcl_kernel_vmlinux_requests.claim(ctx);
76+
let openhcl_kernel_modules_requests = openhcl_kernel_modules_requests.claim(ctx);
77+
let uefi_mu_msvm_requests = uefi_mu_msvm_requests.claim(ctx);
6078

6179
move |rt| {
6280
// Read Nix environment variables
@@ -87,6 +105,48 @@ impl FlowNode for Node {
87105
rt.write_all(protoc_requests, &protoc_path);
88106
}
89107

108+
// Read and write openhcl_kernel vmlinux path if requested
109+
if !openhcl_kernel_vmlinux_requests.is_empty() {
110+
let kernel_vmlinux = std::env::var("NIX_OPENHCL_KERNEL_VMLINUX").context(
111+
"NIX_OPENHCL_KERNEL_VMLINUX not set - ensure shell.nix exports this variable",
112+
)?;
113+
let kernel_vmlinux_path = PathBuf::from(&kernel_vmlinux);
114+
115+
log::info!(
116+
"Resolved Nix openhcl_kernel vmlinux: {}",
117+
kernel_vmlinux_path.display()
118+
);
119+
rt.write_all(openhcl_kernel_vmlinux_requests, &kernel_vmlinux_path);
120+
}
121+
122+
// Read and write openhcl_kernel modules path if requested
123+
if !openhcl_kernel_modules_requests.is_empty() {
124+
let kernel_modules = std::env::var("NIX_OPENHCL_KERNEL_MODULES").context(
125+
"NIX_OPENHCL_KERNEL_MODULES not set - ensure shell.nix exports this variable",
126+
)?;
127+
let kernel_modules_path = PathBuf::from(&kernel_modules);
128+
129+
log::info!(
130+
"Resolved Nix openhcl_kernel modules: {}",
131+
kernel_modules_path.display()
132+
);
133+
rt.write_all(openhcl_kernel_modules_requests, &kernel_modules_path);
134+
}
135+
136+
// Read and write UEFI firmware path if requested
137+
if !uefi_mu_msvm_requests.is_empty() {
138+
let uefi_mu_msvm = std::env::var("NIX_UEFI_MU_MSVM").context(
139+
"NIX_UEFI_MU_MSVM not set - ensure shell.nix exports this variable",
140+
)?;
141+
let uefi_mu_msvm_path = PathBuf::from(&uefi_mu_msvm);
142+
143+
log::info!(
144+
"Resolved Nix UEFI firmware: {}",
145+
uefi_mu_msvm_path.display()
146+
);
147+
rt.write_all(uefi_mu_msvm_requests, &uefi_mu_msvm_path);
148+
}
149+
90150
Ok(())
91151
}
92152
});

flowey/flowey_lib_hvlite/src/download_openhcl_kernel_package.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum OpenhclKernelPackageArch {
2222

2323
flowey_request! {
2424
pub enum Request {
25+
/// Use a locally provided kernel package directory
26+
LocalPath(ReadVar<PathBuf>),
2527
/// Specify version string to use for each package kind
2628
Version(OpenhclKernelPackageKind, String),
2729
/// Download the specified kernel package
@@ -44,6 +46,7 @@ impl FlowNode for Node {
4446
}
4547

4648
fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
49+
let mut local_path: Option<ReadVar<PathBuf>> = None;
4750
let mut versions: BTreeMap<OpenhclKernelPackageKind, String> = BTreeMap::new();
4851
let mut reqs: BTreeMap<
4952
(OpenhclKernelPackageKind, OpenhclKernelPackageArch),
@@ -52,6 +55,9 @@ impl FlowNode for Node {
5255

5356
for req in requests {
5457
match req {
58+
Request::LocalPath(path) => {
59+
same_across_all_reqs_backing_var("LocalPath", &mut local_path, path)?
60+
}
5561
Request::Version(arch, v) => {
5662
let mut old = versions.insert(arch, v.clone());
5763
same_across_all_reqs("SetVersion", &mut old, v)?
@@ -62,9 +68,15 @@ impl FlowNode for Node {
6268
}
6369
}
6470

65-
for req_kind in reqs.keys().map(|(k, _)| k) {
66-
if !versions.contains_key(req_kind) {
67-
anyhow::bail!("missing SetVersion for {:?}", req_kind)
71+
if local_path.is_some() && !versions.is_empty() {
72+
anyhow::bail!("Cannot specify both Version and LocalPath");
73+
}
74+
75+
if local_path.is_none() {
76+
for req_kind in reqs.keys().map(|(k, _)| k) {
77+
if !versions.contains_key(req_kind) {
78+
anyhow::bail!("missing SetVersion for {:?}", req_kind)
79+
}
6880
}
6981
}
7082

@@ -74,6 +86,23 @@ impl FlowNode for Node {
7486
return Ok(());
7587
}
7688

89+
// If local path provided, use it directly
90+
if let Some(local_path) = local_path {
91+
ctx.emit_rust_step("use local kernel package", |ctx| {
92+
let local_path = local_path.claim(ctx);
93+
let reqs = reqs.into_values().flatten().collect::<Vec<_>>().claim(ctx);
94+
95+
move |rt| {
96+
let kernel_pkg_dir = rt.read(local_path);
97+
// For local path, the directory itself is the package root
98+
rt.write_all(reqs, &kernel_pkg_dir);
99+
Ok(())
100+
}
101+
});
102+
103+
return Ok(());
104+
}
105+
77106
let extract_zip_deps = flowey_lib_common::_util::extract::extract_zip_if_new_deps(ctx);
78107

79108
for ((kind, arch), out_vars) in reqs {

flowey/flowey_lib_hvlite/src/download_uefi_mu_msvm.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub enum MuMsvmArch {
1414

1515
flowey_request! {
1616
pub enum Request {
17+
/// Use a locally provided UEFI firmware file
18+
LocalPath(ReadVar<PathBuf>),
1719
/// Specify version of mu_msvm to use
1820
Version(String),
1921
/// Download the mu_msvm package for the given arch
@@ -36,23 +38,51 @@ impl FlowNode for Node {
3638

3739
fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
3840
let mut version = None;
41+
let mut local_path: Option<ReadVar<PathBuf>> = None;
3942
let mut reqs: BTreeMap<MuMsvmArch, Vec<WriteVar<PathBuf>>> = BTreeMap::new();
4043

4144
for req in requests {
4245
match req {
46+
Request::LocalPath(path) => {
47+
same_across_all_reqs_backing_var("LocalPath", &mut local_path, path)?
48+
}
4349
Request::Version(v) => same_across_all_reqs("Version", &mut version, v)?,
4450
Request::GetMsvmFd { arch, msvm_fd } => reqs.entry(arch).or_default().push(msvm_fd),
4551
}
4652
}
4753

48-
let version = version.ok_or(anyhow::anyhow!("Missing essential request: Version"))?;
54+
if version.is_some() && local_path.is_some() {
55+
anyhow::bail!("Cannot specify both Version and LocalPath");
56+
}
57+
58+
if version.is_none() && local_path.is_none() {
59+
anyhow::bail!("Must specify a Version or LocalPath request");
60+
}
4961

5062
// -- end of req processing -- //
5163

5264
if reqs.is_empty() {
5365
return Ok(());
5466
}
5567

68+
// If local path provided, use it directly
69+
if let Some(local_path) = local_path {
70+
ctx.emit_rust_step("use local UEFI firmware", |ctx| {
71+
let local_path = local_path.claim(ctx);
72+
let reqs = reqs.into_values().flatten().collect::<Vec<_>>().claim(ctx);
73+
74+
move |rt| {
75+
let msvm_fd = rt.read(local_path);
76+
rt.write_all(reqs, &msvm_fd);
77+
Ok(())
78+
}
79+
});
80+
81+
return Ok(());
82+
}
83+
84+
let version = version.expect("checked above");
85+
5686
let extract_zip_deps = flowey_lib_common::_util::extract::extract_zip_if_new_deps(ctx);
5787

5888
for (arch, out_vars) in reqs {

shell.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ in pkgs.mkShell.override { } {
5050
# CARGO_BUILD_ARGS = "--use-local-deps --custom-openvmm-deps ${openvmm_deps} --custom-uefi=${uefi_mu_msvm}/MSVM.fd --custom-kernel-pkg ${openhcl_kernel} --custom-kernel ${openhcl_kernel}/vmlinux --custom-kernel-modules ${openhcl_kernel}/modules --custom-protoc ${protoc}";
5151
OPENVMM_DEPS = openvmm_deps;
5252
NIX_PROTOC_PATH = protoc;
53+
NIX_OPENHCL_KERNEL_VMLINUX = "${openhcl_kernel}/vmlinux";
54+
NIX_OPENHCL_KERNEL_MODULES = "${openhcl_kernel}/modules";
55+
NIX_UEFI_MU_MSVM = "${uefi_mu_msvm}/MSVM.fd";
5356
RUST_BACKTRACE = 1;
5457
# will probably need more than one of these for local source + dependencies.
5558
# RUSTFLAGS = "--remap-path-prefix =/src";

0 commit comments

Comments
 (0)