5 files changed
--- /dev/null
+++ b/crates/fleet-base/build.rs
@@ -0,0 +1,15 @@
+use std::env;
+
+fn main() {
+ let target = env::var("TARGET").expect("TARGET env var is set by cargo");
+
+ let nix_system = if target.starts_with("x86_64-unknown-linux-") {
+ "x86_64-linux"
+ } else if target.starts_with("aarch64-unknown-linux-") {
+ "aarch64-linux"
+ } else {
+ panic!("unknown nix system name for rust {target} triple!");
+ };
+
+ println!("cargo:rustc-env=NIX_SYSTEM={nix_system}");
+}
88
9use anyhow::Result;9use anyhow::Result;
10use clap::Parser;10use clap::Parser;
11use nix_eval::{nix_go, nix_go_json, util::assert_warn, NixSessionPool, Value};11use nix_eval::{nix_go, util::assert_warn, NixSessionPool, Value};
12use nom::{12use nom::{
13 bytes::complete::take_while1,13 bytes::complete::take_while1,
14 character::complete::char,14 character::complete::char,
8585
86 86
87 87
88
89 #[clap(long, default_value = "detect")]88 #[clap(long, default_value = env!("NIX_SYSTEM"))]
90 pub local_system: String,89 pub local_system: String,
91}90}
9291
184186
185 let pool = NixSessionPool::new(directory.as_os_str().to_owned(), nix_args.clone()).await?;187 let pool = NixSessionPool::new(
188 directory.as_os_str().to_owned(),
189 nix_args.clone(),
190 self.local_system.clone(),
191 )
192 .await?;
186 let nix_session = pool.get().await?;193 let nix_session = pool.get().await?;
187194
188 let builtins_field = Value::binding(nix_session.clone(), "builtins").await?;195 let builtins_field = Value::binding(nix_session.clone(), "builtins").await?;
189 let local_system = if self.local_system == "detect" {
190 nix_go_json!(builtins_field.currentSystem)
191 } else {
192 self.local_system.clone()
193 };
194196
195 let mut fleet_data_path = directory.clone();197 let mut fleet_data_path = directory.clone();
196 fleet_data_path.push("fleet.nix");198 fleet_data_path.push("fleet.nix");
210212
211 let default_pkgs = nix_go!(nixpkgs(Obj {213 let default_pkgs = nix_go!(nixpkgs(Obj {
212 overlays,214 overlays,
213 system: local_system.clone(),215 system: self.local_system.clone(),
214 }));216 }));
215217
216 Ok(Config(Arc::new(FleetConfigInternals {218 Ok(Config(Arc::new(FleetConfigInternals {
217 nix_session,219 nix_session,
218 directory,220 directory,
219 data,221 data,
220 local_system,222 local_system: self.local_system.clone(),
221 nix_args,223 nix_args,
222 config_field,224 config_field,
223 default_pkgs,225 default_pkgs,
--- a/crates/nix-eval/src/lib.rs
+++ b/crates/nix-eval/src/lib.rs
@@ -41,8 +41,8 @@
#[instrument(skip(session, values))]
async fn build_multiple(name: String, session: NixSession, values: Vec<Value>) -> Result<()> {
+ let system = session.0.lock().await.nix_system.clone();
let builtins = Value::binding(session, "builtins").await?;
- let system = nix_go!(builtins.currentSystem);
let drv = nix_go!(builtins.derivation(Obj {
system,
name,
--- a/crates/nix-eval/src/pool.rs
+++ b/crates/nix-eval/src/pool.rs
@@ -1,18 +1,23 @@
-use std::ffi::OsString;
-use std::sync::{Arc, OnceLock};
+use std::{
+ ffi::OsString,
+ sync::{Arc, OnceLock},
+};
use r2d2::Pool;
-use crate::session::NixSessionInner;
-use crate::{Error, NixSession, Result};
+use crate::{session::NixSessionInner, Error, NixSession, Result};
pub struct NixSessionPool(Pool<NixSessionPoolInner>);
impl NixSessionPool {
- pub async fn new(flake: OsString, nix_args: Vec<OsString>) -> Result<Self> {
+ pub async fn new(flake: OsString, nix_args: Vec<OsString>, nix_system: String) -> Result<Self> {
let inner = tokio::task::block_in_place(|| {
r2d2::Builder::<NixSessionPoolInner>::new()
.min_idle(Some(0))
- .build(NixSessionPoolInner { flake, nix_args })
+ .build(NixSessionPoolInner {
+ flake,
+ nix_args,
+ nix_system,
+ })
})?;
Ok(Self(inner))
}
@@ -25,6 +30,7 @@
pub(crate) struct NixSessionPoolInner {
flake: OsString,
nix_args: Vec<OsString>,
+ pub(crate) nix_system: String,
}
impl r2d2::ManageConnection for NixSessionPoolInner {
@@ -38,6 +44,7 @@
Ok(futures::executor::block_on(NixSessionInner::new(
self.flake.as_os_str(),
self.nix_args.iter().map(OsString::as_os_str),
+ self.nix_system.clone(),
))?)
}
--- a/crates/nix-eval/src/session.rs
+++ b/crates/nix-eval/src/session.rs
@@ -206,6 +206,8 @@
next_id: u32,
pub(crate) free_list: Vec<u32>,
+
+ pub nix_system: String,
}
/// Discover inter-message repl delimiter
@@ -222,6 +224,7 @@
pub(crate) async fn new(
flake: &OsStr,
extra_args: impl IntoIterator<Item = &OsStr>,
+ nix_system: String,
) -> Result<Self> {
let mut cmd = Command::new("nix");
cmd.arg("repl")
@@ -280,6 +283,8 @@
next_id: 0,
free_list: vec![],
+
+ nix_system,
};
res.train().await?;
Ok(res)