include Config open Lwt.Syntax let ( <| ) = ( @@ ) let send_noti noti ~body ~icon = Lwt.catch (fun () -> let* new_noti = match !noti with | Some n -> Notification.notify ~replace:n ~summary:"smooooth" ~body ~icon () | None -> Notification.notify ~summary:"smooooth" ~body ~icon () in noti := Some new_noti; Lwt.return_unit) (fun _ -> Lwt.return_unit) let silence silent f = if silent then Lwt.return_unit else f () let main config_path blockers = let noti = ref None in let rec loop () = (* TODO different actions depending on event? *) let* _, _, _, path = Watch.watch_changes config_path in let main_loop () = let* () = send_noti noti ~body:"Awaiting blockers." ~icon:"info" in let* () = Lwt_io.printlf "awaiting blockers" in let* () = Proc.await_blockers ~config_path ~blockers in let* () = send_noti noti ~body:"Rebuilding NixOS config." ~icon:"info" in let* () = Lwt_io.printlf "rebuilding config" in let* res = Build.rebuild_conf config_path in let* () = match res with | true -> let* () = send_noti noti ~body:"New config built and activated.\nAwaiting further changes." ~icon:"info" in Lwt_io.printlf "complete" | false -> let* () = send_noti noti ~body:"Error building and activating config.\nAwaiting further changes." ~icon:"info" in Lwt_io.printlf "build error" in loop () in match path with | Some p when not (p = "flake.lock") -> main_loop () | None -> main_loop () | Some _ -> loop () in let* () = Lwt_io.printlf "awaiting changes" in let* () = send_noti noti ~body:"Awaiting config changes." ~icon:"info" in loop ()