Skip to content

Commit

Permalink
evaluate typhonJobs for the current system
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 23, 2023
1 parent bfad10a commit 97bd460
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion typhon/src/evaluations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::schema::builds::dsl::*;
use crate::schema::evaluations::dsl::*;
use crate::schema::jobs::dsl::*;
use crate::schema::jobsets::dsl::*;
use crate::CURRENT_SYSTEM;
use crate::EVALUATIONS;
use crate::{handles, responses};
use crate::{log_event, Event};
Expand Down Expand Up @@ -133,7 +134,10 @@ impl Evaluation {
let handle = self.handle().await.unwrap(); // TODO
let id = self.evaluation_id;
let task = async move {
let expr = format!("{}#typhonJobs", self.evaluation_flake_locked);
let expr = format!(
"{}#typhonJobs.{}",
self.evaluation_flake_locked, *CURRENT_SYSTEM,
);
let mut jobs_ = JobDrvMap::new();
for job in nix::eval(expr.clone())
.await?
Expand Down
1 change: 1 addition & 0 deletions typhon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub static CONNECTION: Lazy<Connection> = Lazy::new(|| {
pub static LISTENERS: Lazy<Mutex<listeners::Listeners>> =
Lazy::new(|| Mutex::new(listeners::Listeners::new()));
pub static BUILD_LOGS: Lazy<logs::live::Cache<nix::DrvPath>> = Lazy::new(logs::live::Cache::new);
pub static CURRENT_SYSTEM: Lazy<String> = Lazy::new(nix::current_system);

pub async fn connection<'a>() -> tokio::sync::MutexGuard<'a, SqliteConnection> {
CONNECTION.conn.lock().await
Expand Down
17 changes: 17 additions & 0 deletions typhon/src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,23 @@ pub async fn eval(expr: String) -> Result<serde_json::Value, Error> {
)?)
}

pub fn current_system() -> String {
String::from_utf8(
std::process::Command::new("nix")
.args([
"eval",
"--impure",
"--raw",
"--expr",
"builtins.currentSystem",
])
.output()
.unwrap()
.stdout,
)
.unwrap()
}

pub async fn lock(flake_url: &String) -> Result<String, Error> {
let output = Command::nix(["flake", "metadata", "--refresh", "--json"])
.arg(flake_url.clone())
Expand Down

0 comments on commit 97bd460

Please sign in to comment.