#include <filesystem> #include <fstream> #include <iostream> #include <string> #include <vector> 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<struct root_t> get_roots_for_path(string path) { 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 roots; }