From 6404fcf0c12b10a5357f1140ad658e7d43e10310 Mon Sep 17 00:00:00 2001 From: Kaiden Fey Date: Sun, 6 Sep 2020 20:25:05 +0200 Subject: stage1: implementing available root iteration --- stage1/lib/root.h | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'stage1/lib/root.h') 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 +#include #include #include -#include +#include +#include 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 get_roots_for_path(string path) { - for(auto &entry: fs::recursive_directory_iterator(path)) { - std::cout << entry.path() << std::endl; + vector 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; } -- cgit v1.2.3