#include #include #include #include #include using std::string; using std::vector; namespace fs = std::filesystem; /** Root build type */ enum r_type { FULL_NIXOS, FULL_DARWIN, PARTIAL, COLLECTION, }; /** Root metadata */ struct root_t { string name; string path; enum r_type type; }; vector get_roots_for_path(string path) { 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 roots; }