From 2bd57d4d36f66de00fa4f791569056e58598e782 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Sat, 27 Apr 2024 13:24:39 -0600 Subject: refactor some nix-env and profile code to libcmd Notably, ProfileManifest and ProfileElement are useful generic profile management code, and nix profile is not the only place in the codebase where profiles are relevant. This commit is in preparation for fixing upgrade-nix's interaction with new-style profiles. Change-Id: Iefc8bbd34b4bc6012175cb3d6e6a8207973bc792 --- src/libcmd/cmd-profiles.hh | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/libcmd/cmd-profiles.hh (limited to 'src/libcmd/cmd-profiles.hh') diff --git a/src/libcmd/cmd-profiles.hh b/src/libcmd/cmd-profiles.hh new file mode 100644 index 000000000..d03f9b1c2 --- /dev/null +++ b/src/libcmd/cmd-profiles.hh @@ -0,0 +1,73 @@ +#pragma once +///@file + +#include "built-path.hh" +#include "eval.hh" +#include "flake/flakeref.hh" +#include "get-drvs.hh" +#include "types.hh" + +#include +#include + +#include + +namespace nix +{ + +struct ProfileElementSource +{ + FlakeRef originalRef; + // FIXME: record original attrpath. + FlakeRef lockedRef; + std::string attrPath; + ExtendedOutputsSpec outputs; + + bool operator<(const ProfileElementSource & other) const; + + std::string to_string() const; +}; + +constexpr int DEFAULT_PRIORITY = 5; + +struct ProfileElement +{ + StorePathSet storePaths; + std::optional source; + bool active = true; + int priority = DEFAULT_PRIORITY; + + std::string identifier() const; + + /** + * Return a string representing an installable corresponding to the current + * element, either a flakeref or a plain store path + */ + std::set toInstallables(Store & store); + + std::string versions() const; + + bool operator<(const ProfileElement & other) const; + + void updateStorePaths(ref evalStore, ref store, const BuiltPaths & builtPaths); +}; + +struct ProfileManifest +{ + std::vector elements; + + ProfileManifest() { } + + ProfileManifest(EvalState & state, const Path & profile); + + nlohmann::json toJSON(Store & store) const; + + StorePath build(ref store); + + static void printDiff(const ProfileManifest & prev, const ProfileManifest & cur, std::string_view indent); +}; + +DrvInfos queryInstalled(EvalState & state, const Path & userEnv); +std::string showVersions(const std::set & versions); + +} -- cgit v1.2.3