aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcmd')
-rw-r--r--src/libcmd/cmd-profiles.cc26
-rw-r--r--src/libcmd/cmd-profiles.hh3
2 files changed, 29 insertions, 0 deletions
diff --git a/src/libcmd/cmd-profiles.cc b/src/libcmd/cmd-profiles.cc
index 4d8ff7438..5fa7f902c 100644
--- a/src/libcmd/cmd-profiles.cc
+++ b/src/libcmd/cmd-profiles.cc
@@ -1,6 +1,9 @@
+#include <set>
+
#include "cmd-profiles.hh"
#include "built-path.hh"
#include "builtins/buildenv.hh"
+#include "logging.hh"
#include "names.hh"
#include "store-api.hh"
@@ -106,6 +109,8 @@ ProfileManifest::ProfileManifest(EvalState & state, const Path & profile)
if (pathExists(manifestPath)) {
auto json = nlohmann::json::parse(readFile(manifestPath));
+ // Keep track of already found names so we can prevent duplicates.
+ std::set<std::string> foundNames;
auto version = json.value("version", 0);
std::string sUrl;
@@ -139,6 +144,26 @@ ProfileManifest::ProfileManifest(EvalState & state, const Path & profile)
e["attrPath"],
e["outputs"].get<ExtendedOutputsSpec>()};
}
+
+ std::string nameCandidate(element.identifier());
+
+ if (e.contains("name")) {
+ nameCandidate = e["name"];
+ } else if (element.source) {
+ auto const url = parseURL(element.source->to_string());
+ auto const name = getNameFromURL(url);
+ if (name) {
+ nameCandidate = *name;
+ }
+ }
+
+ auto finalName = nameCandidate;
+ for (unsigned appendedIndex = 1; foundNames.contains(finalName); ++appendedIndex) {
+ finalName = nameCandidate + std::to_string(appendedIndex);
+ }
+ element.name = finalName;
+ foundNames.insert(element.name);
+
elements.emplace_back(std::move(element));
}
} else if (pathExists(profile + "/manifest.nix")) {
@@ -151,6 +176,7 @@ ProfileManifest::ProfileManifest(EvalState & state, const Path & profile)
for (auto & drvInfo : drvInfos) {
ProfileElement element;
element.storePaths = {drvInfo.queryOutPath()};
+ element.name = element.identifier();
elements.emplace_back(std::move(element));
}
}
diff --git a/src/libcmd/cmd-profiles.hh b/src/libcmd/cmd-profiles.hh
index d03f9b1c2..7f2c8a76f 100644
--- a/src/libcmd/cmd-profiles.hh
+++ b/src/libcmd/cmd-profiles.hh
@@ -6,6 +6,8 @@
#include "flake/flakeref.hh"
#include "get-drvs.hh"
#include "types.hh"
+#include "url.hh"
+#include "url-name.hh"
#include <string>
#include <set>
@@ -33,6 +35,7 @@ constexpr int DEFAULT_PRIORITY = 5;
struct ProfileElement
{
StorePathSet storePaths;
+ std::string name;
std::optional<ProfileElementSource> source;
bool active = true;
int priority = DEFAULT_PRIORITY;