diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 5260e65..0000000 --- a/flake.lock +++ /dev/null @@ -1,48 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1771008912, - "narHash": "sha256-gf2AmWVTs8lEq7z/3ZAsgnZDhWIckkb+ZnAo5RzSxJg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a82ccc39b39b621151d6732718e3e250109076fa", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1771125043, - "narHash": "sha256-ldf/s49n6rOAxl7pYLJGGS1N/assoHkCOWdEdLyNZkc=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "4912f951a26dc8142b176be2c2ad834319dc06e8", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index 7ee9895..da2233d 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -94,6 +94,7 @@ async fn build_target( build_directory, flake_directory, target_config.get_attr()?, + target_config.get_name()?, ) .await?; diff --git a/src/config/target.rs b/src/config/target.rs index d737f35..968350c 100644 --- a/src/config/target.rs +++ b/src/config/target.rs @@ -121,6 +121,11 @@ impl TargetConfig { pub(crate) fn get_attr(&'_ self) -> Result<&String, CustomError> { Ok(&self.attr) } + + /// The name to identify this target + pub(crate) fn get_name(&'_ self) -> Result<&String, CustomError> { + Ok(&self.name) + } } fn hex_string(data: &[u8]) -> String { diff --git a/src/nix_util/high_level.rs b/src/nix_util/high_level.rs index 6690ca4..f96e5d9 100644 --- a/src/nix_util/high_level.rs +++ b/src/nix_util/high_level.rs @@ -10,16 +10,18 @@ use crate::database::db_handle::DbHandle; use super::running_build::RunningBuild; -pub(crate) async fn nixos_build_target( +pub(crate) async fn nixos_build_target( db_handle: &DbHandle, build_path: B, flake_path: F, attr: A, + target_name: TN, ) -> Result<()> where B: AsRef, F: AsRef, A: AsRef, + TN: AsRef, { let reference = { let path = AsRef::::as_ref(flake_path.as_ref()); @@ -55,7 +57,7 @@ where let child = command.spawn()?; let mut running_build = RunningBuild::new(db_handle)?; - running_build.run_to_completion(child).await?; + running_build.run_to_completion(child, target_name).await?; Ok(()) } diff --git a/src/nix_util/running_build.rs b/src/nix_util/running_build.rs index 04e0e08..14fed46 100644 --- a/src/nix_util/running_build.rs +++ b/src/nix_util/running_build.rs @@ -1,3 +1,4 @@ +use sqlx::Row; use tokio::io::AsyncBufReadExt; use tokio::io::BufReader; use tokio::io::Lines; @@ -17,7 +18,22 @@ impl<'db> RunningBuild<'db> { Ok(RunningBuild { db_handle }) } - pub(crate) async fn run_to_completion(&mut self, mut child: Child) -> Result<()> { + pub(crate) async fn run_to_completion( + &mut self, + mut child: Child, + target_name: TN, + ) -> Result<()> + where + TN: AsRef, + { + let build_id: i64 = sqlx::query( + r#"INSERT INTO build (start_time, target) SELECT unixepoch('now'), ? RETURNING id"#, + ) + .bind(target_name.as_ref()) + .fetch_one(&self.db_handle.conn) + .await? + .try_get("id")?; + let mut output_stream = OutputStream::from_child(&mut child)?; let exit_status_handle = tokio::spawn(async move { @@ -41,6 +57,19 @@ impl<'db> RunningBuild<'db> { let exit_status = exit_status_handle.await?; println!("nixos-rebuild status was: {}", exit_status); + let update: u64 = + sqlx::query(r#"UPDATE build SET end_time=unixepoch('now'), status=? WHERE id=?"#) + .bind( + exit_status + .code() + .expect("Process should have an exit code."), + ) + .bind(build_id) + .execute(&self.db_handle.conn) + .await? + .rows_affected(); + assert!(update == 1); + Ok(()) }