aboutsummaryrefslogtreecommitdiff
path: root/stage1/lib/root.h
diff options
context:
space:
mode:
Diffstat (limited to 'stage1/lib/root.h')
-rw-r--r--stage1/lib/root.h51
1 files changed, 41 insertions, 10 deletions
diff --git a/stage1/lib/root.h b/stage1/lib/root.h
index 3fbca0c5367..c6470bccdfa 100644
--- a/stage1/lib/root.h
+++ b/stage1/lib/root.h
@@ -1,9 +1,11 @@
-#include <string>
+#include <filesystem>
#include <fstream>
#include <iostream>
-#include <filesystem>
+#include <string>
+#include <vector>
using std::string;
+using std::vector;
namespace fs = std::filesystem;
/** Root build type */
@@ -22,15 +24,44 @@ struct root_t {
};
-root_t get_root(string path)
+vector<struct root_t> get_roots_for_path(string path)
{
- for(auto &entry: fs::recursive_directory_iterator(path)) {
- std::cout << entry.path() << std::endl;
+ vector<struct root_t> roots;
+
+ for(auto &entry: fs::directory_iterator(path)) {
+ auto path = entry.path();
+
+ if (path.extension() == ".nix") {
+ // simple root
+ roots.push_back(root_t {
+ path.filename(),
+ path.string(),
+ FULL_NIXOS,
+ });
+
+ } else {
+ path /= "default.nix";
+ bool exists = fs::exists(path);
+ path = path.parent_path();
+
+ if (exists) {
+ // nested single root
+ roots.push_back(root_t {
+ path.filename(),
+ path.string(),
+ FULL_NIXOS,
+ });
+ } else {
+ // nested single root
+ roots.push_back(root_t {
+ path.filename(),
+ path.string(),
+ COLLECTION,
+ });
+ }
+ }
+
}
- return root_t {
- "hyperion",
- "roots/hyperion/default.nix",
- FULL_NIXOS,
- };
+ return roots;
}