difftreelog
refactor replace builtins.currentSystem with pure alternative
in: trunk
5 files changed
crates/fleet-base/build.rsdiffbeforeafterboth--- /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}");
+}
crates/fleet-base/src/opts.rsdiffbeforeafterboth--- a/crates/fleet-base/src/opts.rs
+++ b/crates/fleet-base/src/opts.rs
@@ -8,7 +8,7 @@
use anyhow::Result;
use clap::Parser;
-use nix_eval::{nix_go, nix_go_json, util::assert_warn, NixSessionPool, Value};
+use nix_eval::{nix_go, util::assert_warn, NixSessionPool, Value};
use nom::{
bytes::complete::take_while1,
character::complete::char,
@@ -85,14 +85,16 @@
/// Override detected system for host, to perform builds via
/// binfmt-declared qemu instead of trying to crosscompile
- // TODO: Remove, as it is not used anymore.
- #[clap(long, default_value = "detect")]
+ #[clap(long, default_value = env!("NIX_SYSTEM"))]
pub local_system: String,
}
impl FleetOpts {
- pub async fn filter_skipped(&self, hosts: impl IntoIterator<Item = ConfigHost>) -> Result<Vec<ConfigHost>> {
- let mut out = Vec::new();
+ pub async fn filter_skipped(
+ &self,
+ hosts: impl IntoIterator<Item = ConfigHost>,
+ ) -> Result<Vec<ConfigHost>> {
+ let mut out = Vec::new();
for host in hosts {
if self.should_skip(&host).await? {
continue;
@@ -182,15 +184,15 @@
pub async fn build(&self, nix_args: Vec<OsString>) -> Result<Config> {
let directory = current_dir()?;
- let pool = NixSessionPool::new(directory.as_os_str().to_owned(), nix_args.clone()).await?;
+ let pool = NixSessionPool::new(
+ directory.as_os_str().to_owned(),
+ nix_args.clone(),
+ self.local_system.clone(),
+ )
+ .await?;
let nix_session = pool.get().await?;
let builtins_field = Value::binding(nix_session.clone(), "builtins").await?;
- let local_system = if self.local_system == "detect" {
- nix_go_json!(builtins_field.currentSystem)
- } else {
- self.local_system.clone()
- };
let mut fleet_data_path = directory.clone();
fleet_data_path.push("fleet.nix");
@@ -210,14 +212,14 @@
let default_pkgs = nix_go!(nixpkgs(Obj {
overlays,
- system: local_system.clone(),
+ system: self.local_system.clone(),
}));
Ok(Config(Arc::new(FleetConfigInternals {
nix_session,
directory,
data,
- local_system,
+ local_system: self.local_system.clone(),
nix_args,
config_field,
default_pkgs,
crates/nix-eval/src/lib.rsdiffbeforeafterboth--- 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,
crates/nix-eval/src/pool.rsdiffbeforeafterboth1use std::ffi::OsString;2use std::sync::{Arc, OnceLock};1use std::{2 ffi::OsString,3 sync::{Arc, OnceLock},4};354use r2d2::Pool;6use r2d2::Pool;576use crate::session::NixSessionInner;7use crate::{Error, NixSession, Result};8use crate::{session::NixSessionInner, Error, NixSession, Result};899pub struct NixSessionPool(Pool<NixSessionPoolInner>);10pub struct NixSessionPool(Pool<NixSessionPoolInner>);10impl NixSessionPool {11impl NixSessionPool {11 pub async fn new(flake: OsString, nix_args: Vec<OsString>) -> Result<Self> {12 pub async fn new(flake: OsString, nix_args: Vec<OsString>, nix_system: String) -> Result<Self> {12 let inner = tokio::task::block_in_place(|| {13 let inner = tokio::task::block_in_place(|| {13 r2d2::Builder::<NixSessionPoolInner>::new()14 r2d2::Builder::<NixSessionPoolInner>::new()14 .min_idle(Some(0))15 .min_idle(Some(0))15 .build(NixSessionPoolInner { flake, nix_args })16 .build(NixSessionPoolInner {17 flake,18 nix_args,19 nix_system,20 })16 })?;21 })?;17 Ok(Self(inner))22 Ok(Self(inner))25pub(crate) struct NixSessionPoolInner {30pub(crate) struct NixSessionPoolInner {26 flake: OsString,31 flake: OsString,27 nix_args: Vec<OsString>,32 nix_args: Vec<OsString>,33 pub(crate) nix_system: String,28}34}293530impl r2d2::ManageConnection for NixSessionPoolInner {36impl r2d2::ManageConnection for NixSessionPoolInner {38 Ok(futures::executor::block_on(NixSessionInner::new(44 Ok(futures::executor::block_on(NixSessionInner::new(39 self.flake.as_os_str(),45 self.flake.as_os_str(),40 self.nix_args.iter().map(OsString::as_os_str),46 self.nix_args.iter().map(OsString::as_os_str),47 self.nix_system.clone(),41 ))?)48 ))?)42 }49 }4350crates/nix-eval/src/session.rsdiffbeforeafterboth--- 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)