open Lwt.Syntax open Lwt.Infix let run_and_collect cmd = let* list = Lwt_process.pread_lines cmd |> Lwt_stream.to_list in list |> List.fold_left (fun acc el -> acc ^ " " ^ el) "" |> Lwt.return let rebuild_conf path = let* dir = Lwt_io.create_temp_dir ~suffix:"smooooth" () in let* hostname = Lwt_unix.gethostname () in let* nix_build = Lwt_process.exec ( "nix", [| "nix"; "build"; "--out-link"; dir ^ "/system"; path ^ "#nixosConfigurations." ^ hostname ^ ".config.system.build.toplevel"; |] ) in let* res = match nix_build with | Unix.WEXITED e when e = 0 -> Lwt_process.exec ( "pkexec", [| "pkexec"; dir ^ "/system/bin/switch-to-configuration"; "switch" |] ) >>= fun _ -> Lwt.return_true | _ -> Lwt.return_false (* let* () = Lwt_io.printlf "nix build output:\n%s" nix_build in *) in (* let* () = Lwt_io.printlf "activation output:\n%s" activation in *) let* () = Lwt_io.delete_recursively dir in Lwt.return res (* buffer four to five lines and keep them up in the notification ? *) (* nom-like current-build output ? *) (* catch any build error and try to display it usefully *)