aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/path-with-outputs.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-04-22 15:17:01 +0200
committerEelco Dolstra <edolstra@gmail.com>2022-05-03 13:43:52 +0200
commit4a79cba5118f29b896f3d50164beacd4901ab01f (patch)
tree2159770446fb151e12bf82856b6418201ae23bbf /src/libstore/path-with-outputs.cc
parent404c222444b4c8c60148ccf890cd41611f26b0a0 (diff)
Allow selecting derivation outputs using 'installable!outputs'
E.g. 'nixpkgs#glibc^dev,static' or 'nixpkgs#glibc^*'.
Diffstat (limited to 'src/libstore/path-with-outputs.cc')
-rw-r--r--src/libstore/path-with-outputs.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libstore/path-with-outputs.cc b/src/libstore/path-with-outputs.cc
index 078c117bd..7d180a0f6 100644
--- a/src/libstore/path-with-outputs.cc
+++ b/src/libstore/path-with-outputs.cc
@@ -1,6 +1,8 @@
#include "path-with-outputs.hh"
#include "store-api.hh"
+#include <regex>
+
namespace nix {
std::string StorePathWithOutputs::to_string(const Store & store) const
@@ -68,4 +70,18 @@ StorePathWithOutputs followLinksToStorePathWithOutputs(const Store & store, std:
return StorePathWithOutputs { store.followLinksToStorePath(path), std::move(outputs) };
}
+std::pair<std::string, OutputsSpec> parseOutputsSpec(const std::string & s)
+{
+ static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))");
+
+ std::smatch match;
+ if (!std::regex_match(s, match, regex))
+ return {s, DefaultOutputs()};
+
+ if (match[3].matched)
+ return {match[1], AllOutputs()};
+
+ return {match[1], tokenizeString<OutputNames>(match[4].str(), ",")};
+}
+
}