From 65edbcc37ac81791b2b4bbee16b942de28c79a01 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 7 Feb 2025 00:06:17 +0100 Subject: [PATCH] libcmd: asyncify ProfileManifest::build Change-Id: Ib1d7ce47c81259d305f3e993618516e4c165a084 --- lix/libcmd/cmd-profiles.cc | 8 +++++--- lix/libcmd/cmd-profiles.hh | 2 +- lix/nix/profile.cc | 6 +++--- lix/nix/upgrade-nix.cc | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lix/libcmd/cmd-profiles.cc b/lix/libcmd/cmd-profiles.cc index 2168fa983..c60ad96fb 100644 --- a/lix/libcmd/cmd-profiles.cc +++ b/lix/libcmd/cmd-profiles.cc @@ -223,8 +223,8 @@ nlohmann::json ProfileManifest::toJSON(Store & store) const return json; } -StorePath ProfileManifest::build(ref store) -{ +kj::Promise> ProfileManifest::build(ref store) +try { auto tempDir = createTempDir(); StorePathSet references; @@ -269,7 +269,9 @@ StorePath ProfileManifest::build(ref store) StringSource source(sink.s); store->addToStore(info, source); - return std::move(info.path); + co_return std::move(info.path); +} catch (...) { + co_return result::current_exception(); } void ProfileManifest::printDiff( diff --git a/lix/libcmd/cmd-profiles.hh b/lix/libcmd/cmd-profiles.hh index 71bcc85c7..547c8b4f5 100644 --- a/lix/libcmd/cmd-profiles.hh +++ b/lix/libcmd/cmd-profiles.hh @@ -64,7 +64,7 @@ struct ProfileManifest nlohmann::json toJSON(Store & store) const; - StorePath build(ref store); + kj::Promise> build(ref store); void addElement(std::string_view nameCandidate, ProfileElement element); void addElement(ProfileElement element); diff --git a/lix/nix/profile.cc b/lix/nix/profile.cc index b84ff2307..0f322790d 100644 --- a/lix/nix/profile.cc +++ b/lix/nix/profile.cc @@ -110,7 +110,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile } try { - updateProfile(manifest.build(store)); + updateProfile(aio().blockOn(manifest.build(store))); } catch (BuildEnvFileConflictError & conflictError) { // FIXME use C++20 std::ranges once macOS has it // See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102 @@ -270,7 +270,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem } warn ("Use 'nix profile list' to see the current profile."); } - updateProfile(newManifest.build(store)); + updateProfile(aio().blockOn(newManifest.build(store))); } }; @@ -406,7 +406,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf builtPaths.find(&*installable)->second.first); } - updateProfile(manifest.build(store)); + updateProfile(aio().blockOn(manifest.build(store))); } }; diff --git a/lix/nix/upgrade-nix.cc b/lix/nix/upgrade-nix.cc index 8875061f0..15de76255 100644 --- a/lix/nix/upgrade-nix.cc +++ b/lix/nix/upgrade-nix.cc @@ -255,7 +255,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand manifest.elements.at(nixElemName) = elemForNewNix; // Build the new profile, and switch to it. - StorePath const newProfile = manifest.build(store); + StorePath const newProfile = aio().blockOn(manifest.build(store)); printTalkative("built new profile '%s'", store->printStorePath(newProfile)); auto const newGeneration = aio().blockOn(createGeneration(*fsStore, this->profileDir, newProfile));