git.delta.rocks / jrsonnet / refs/commits / 7de62040eec5

difftreelog

refactor replace builtins.currentSystem with pure alternative

Yaroslav Bolyukin2024-11-30parent: #3e7b063.patch.diff
in: trunk

5 files changed

addedcrates/fleet-base/build.rsdiffbeforeafterboth

no changes

modifiedcrates/fleet-base/src/opts.rsdiffbeforeafterboth
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 /// Override detected system for host, to perform builds via86 /// Override detected system for host, to perform builds via
87 /// binfmt-declared qemu instead of trying to crosscompile87 /// binfmt-declared qemu instead of trying to crosscompile
88 // TODO: Remove, as it is not used anymore.
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,
modifiedcrates/nix-eval/src/lib.rsdiffbeforeafterboth
4141
42#[instrument(skip(session, values))]42#[instrument(skip(session, values))]
43async fn build_multiple(name: String, session: NixSession, values: Vec<Value>) -> Result<()> {43async fn build_multiple(name: String, session: NixSession, values: Vec<Value>) -> Result<()> {
44 let system = session.0.lock().await.nix_system.clone();
44 let builtins = Value::binding(session, "builtins").await?;45 let builtins = Value::binding(session, "builtins").await?;
45 let system = nix_go!(builtins.currentSystem);
46 let drv = nix_go!(builtins.derivation(Obj {46 let drv = nix_go!(builtins.derivation(Obj {
47 system,47 system,
48 name,48 name,
modifiedcrates/nix-eval/src/pool.rsdiffbeforeafterboth
1use std::ffi::OsString;
2use std::sync::{Arc, OnceLock};1use std::{
2 ffi::OsString,
3 sync::{Arc, OnceLock},
4};
35
4use r2d2::Pool;6use r2d2::Pool;
57
6use crate::session::NixSessionInner;
7use crate::{Error, NixSession, Result};8use crate::{session::NixSessionInner, Error, NixSession, Result};
89
9pub 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}
2935
30impl 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 }
4350
modifiedcrates/nix-eval/src/session.rsdiffbeforeafterboth
207 next_id: u32,207 next_id: u32,
208 pub(crate) free_list: Vec<u32>,208 pub(crate) free_list: Vec<u32>,
209
210 pub nix_system: String,
209}211}
210212
211/// Discover inter-message repl delimiter213/// Discover inter-message repl delimiter
222 pub(crate) async fn new(224 pub(crate) async fn new(
223 flake: &OsStr,225 flake: &OsStr,
224 extra_args: impl IntoIterator<Item = &OsStr>,226 extra_args: impl IntoIterator<Item = &OsStr>,
227 nix_system: String,
225 ) -> Result<Self> {228 ) -> Result<Self> {
226 let mut cmd = Command::new("nix");229 let mut cmd = Command::new("nix");
227 cmd.arg("repl")230 cmd.arg("repl")
281 next_id: 0,284 next_id: 0,
282 free_list: vec![],285 free_list: vec![],
286
287 nix_system,
283 };288 };
284 res.train().await?;289 res.train().await?;
285 Ok(res)290 Ok(res)