Add support for parsing the flake.lock.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
use sqlx::Row;
|
||||
use tracing::info;
|
||||
|
||||
use crate::Result;
|
||||
use crate::cli::parameters::BuildArgs;
|
||||
use crate::config::Config;
|
||||
@@ -7,8 +10,10 @@ use crate::fs_util::assert_directory;
|
||||
use crate::fs_util::is_git_repo;
|
||||
use crate::git_util::git_force_into_state;
|
||||
use crate::git_util::git_init_at_rev;
|
||||
use crate::nix_util::FlakeLock;
|
||||
use crate::nix_util::nix_flake_update;
|
||||
use crate::nix_util::nixos_build_target;
|
||||
use crate::nix_util::parse_flake_lock;
|
||||
|
||||
pub(crate) async fn run_build(args: BuildArgs) -> Result<()> {
|
||||
println!("{:?}", args);
|
||||
@@ -101,14 +106,62 @@ async fn build_target(
|
||||
build_directory.to_string_lossy()
|
||||
);
|
||||
|
||||
let target_name = target_config.get_name()?;
|
||||
|
||||
let build_id: i64 = sqlx::query(
|
||||
r#"INSERT INTO build (start_time, target) SELECT unixepoch('now'), ? RETURNING id"#,
|
||||
)
|
||||
.bind(target_name)
|
||||
.fetch_one(&db_handle.conn)
|
||||
.await?
|
||||
.try_get("id")?;
|
||||
|
||||
let flake_lock = parse_flake_lock(&flake_directory).await?;
|
||||
write_input_revs_to_db(db_handle, &flake_lock, build_id).await?;
|
||||
panic!();
|
||||
|
||||
nixos_build_target(
|
||||
db_handle,
|
||||
build_directory,
|
||||
flake_directory,
|
||||
target_config.get_attr()?,
|
||||
target_config.get_name()?,
|
||||
target_name,
|
||||
build_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn write_input_revs_to_db(
|
||||
db_handle: &DbHandle,
|
||||
flake_lock: &FlakeLock,
|
||||
build_id: i64,
|
||||
) -> Result<()> {
|
||||
let root_node = flake_lock.get_root_node()?;
|
||||
let direct_inputs = flake_lock.get_inputs(root_node)?;
|
||||
|
||||
let mut tx = db_handle.conn.begin().await?;
|
||||
for (input, node) in direct_inputs.iter() {
|
||||
let locked = match &node.locked {
|
||||
Some(locked) => locked,
|
||||
None => {
|
||||
info!(
|
||||
"Not recording rev for input {} because it lacks a locked section.",
|
||||
input
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let rev = &locked.rev;
|
||||
info!("input {} {}", input, rev);
|
||||
sqlx::query(r#"INSERT INTO flake_inputs (build_id, input_name, rev) VALUES (?, ?, ?);"#)
|
||||
.bind(build_id)
|
||||
.bind(input)
|
||||
.bind(rev)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user