aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaiden Fey <kookie@spacekookie.de>2020-09-06 20:25:05 +0200
committerKaiden Fey <kookie@spacekookie.de>2020-09-27 22:31:35 +0200
commit6404fcf0c12b10a5357f1140ad658e7d43e10310 (patch)
tree596a3d8869c91b93098b78132293e8831d31b7ff
parentaf7f36b3e8ddce86872a3599101ac68bbab74439 (diff)
stage1: implementing available root iteration
-rw-r--r--stage1/lib/root.h51
-rw-r--r--stage1/main.cpp8
2 files changed, 47 insertions, 12 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;
}
diff --git a/stage1/main.cpp b/stage1/main.cpp
index 6f2cd57fae8..b59582f88fb 100644
--- a/stage1/main.cpp
+++ b/stage1/main.cpp
@@ -5,9 +5,13 @@ int main(int argn, char **argv)
{
std::cout << "I am a builder!" << std::endl;
- get_root("/Users/spacekookie/Projects/code/libkookie/roots");
+ auto v = get_roots_for_path("/Users/spacekookie/Projects/code/libkookie/roots");
+ std::cout << "uwu! " << v.size() << std::endl;
- std::cout << "uwu!" << std::endl;
+ for (auto &entry : v) {
+ std::cout << entry.name << ": " << entry.path << std::endl;
+ }
+
return 0;
}