diff options
-rw-r--r-- | src/libutil/config-impl.hh | 10 | ||||
-rw-r--r-- | src/libutil/config.hh | 26 | ||||
-rw-r--r-- | src/nix/main.cc | 5 | ||||
-rw-r--r-- | src/resolve-system-dependencies/resolve-system-dependencies.cc | 190 |
4 files changed, 35 insertions, 196 deletions
diff --git a/src/libutil/config-impl.hh b/src/libutil/config-impl.hh index 756175f95..8e3a1e408 100644 --- a/src/libutil/config-impl.hh +++ b/src/libutil/config-impl.hh @@ -66,9 +66,13 @@ void BaseSetting<T>::appendOrSet(T newValue, bool append) template<typename T> void BaseSetting<T>::set(const std::string & str, bool append) { - if (experimentalFeatureSettings.isEnabled(experimentalFeature)) - appendOrSet(parse(str), append); - else { + if (experimentalFeatureSettings.isEnabled(experimentalFeature)) { + auto parsed = parse(str); + if (deprecated && (append || parsed != value)) { + warn("deprecated setting '%s' found (set to '%s')", name, str); + } + appendOrSet(std::move(parsed), append); + } else { assert(experimentalFeature); warn("Ignoring setting '%s' because experimental feature '%s' is not enabled", name, diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 8a4d24456..d7bf9cdc9 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -175,6 +175,10 @@ class AbstractSetting public: + struct deprecated_t { + explicit deprecated_t() = default; + }; + const std::string name; const std::string description; const std::set<std::string> aliases; @@ -225,6 +229,7 @@ protected: T value; const T defaultValue; const bool documentDefault; + const bool deprecated; /** * Parse the string into a `T`. @@ -250,11 +255,13 @@ public: const std::string & name, const std::string & description, const std::set<std::string> & aliases = {}, - std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) + std::optional<ExperimentalFeature> experimentalFeature = std::nullopt, + bool deprecated = false) : AbstractSetting(name, description, aliases, experimentalFeature) , value(def) , defaultValue(def) , documentDefault(documentDefault) + , deprecated(deprecated) { } operator const T &() const { return value; } @@ -322,12 +329,25 @@ public: const std::string & description, const std::set<std::string> & aliases = {}, const bool documentDefault = true, - std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) - : BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature)) + std::optional<ExperimentalFeature> experimentalFeature = std::nullopt, + bool deprecated = false) + : BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature), deprecated) { options->addSetting(this); } + Setting(AbstractSetting::deprecated_t, + Config * options, + const T & def, + const std::string & name, + const std::string & description, + const std::set<std::string> & aliases = {}, + const bool documentDefault = true, + std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) + : Setting(options, def, name, description, aliases, documentDefault, std::move(experimentalFeature), true) + { + } + void operator =(const T & v) { this->assign(v); } }; diff --git a/src/nix/main.cc b/src/nix/main.cc index 981aa2fc5..1c1e9df7e 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -503,6 +503,11 @@ void mainWrapped(int argc, char * * argv) int main(int argc, char * * argv) { + if (argc < 1) { + std::cerr << "no, we don't have pkexec at home. provide argv[0]." << std::endl; + std::abort(); + } + // Increase the default stack size for the evaluator and for // libstdc++'s std::regex. nix::setStackSize(64 * 1024 * 1024); diff --git a/src/resolve-system-dependencies/resolve-system-dependencies.cc b/src/resolve-system-dependencies/resolve-system-dependencies.cc deleted file mode 100644 index 319f7108e..000000000 --- a/src/resolve-system-dependencies/resolve-system-dependencies.cc +++ /dev/null @@ -1,190 +0,0 @@ -#include "derivations.hh" -#include "globals.hh" -#include "shared.hh" -#include "store-api.hh" -#include <sys/utsname.h> -#include <algorithm> -#include <iostream> -#include <fstream> -#include <sys/mman.h> -#include <fcntl.h> -#include <mach-o/loader.h> -#include <mach-o/swap.h> - -#define DO_SWAP(x, y) ((x) ? OSSwapInt32(y) : (y)) - -using namespace nix; - -static auto cacheDir = Path{}; - -Path resolveCacheFile(Path lib) -{ - std::replace(lib.begin(), lib.end(), '/', '%'); - return cacheDir + "/" + lib; -} - -std::set<std::string> readCacheFile(const Path & file) -{ - return tokenizeString<std::set<std::string>>(readFile(file), "\n"); -} - -std::set<std::string> runResolver(const Path & filename) -{ - AutoCloseFD fd{open(filename.c_str(), O_RDONLY)}; - if (!fd) - throw SysError("opening '%s'", filename); - - struct stat st; - if (fstat(fd.get(), &st)) - throw SysError("statting '%s'", filename); - - if (!S_ISREG(st.st_mode)) { - printError("file '%s' is not a regular MACH binary", filename); - return {}; - } - - if (st.st_size < sizeof(mach_header_64)) { - printError("file '%s' is too short for a MACH binary", filename); - return {}; - } - - char* obj = (char*) mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd.get(), 0); - if (!obj) - throw SysError("mmapping '%s'", filename); - - ptrdiff_t mach64_offset = 0; - - uint32_t magic = ((mach_header_64*) obj)->magic; - if (magic == FAT_CIGAM || magic == FAT_MAGIC) { - bool should_swap = magic == FAT_CIGAM; - uint32_t narches = DO_SWAP(should_swap, ((fat_header *) obj)->nfat_arch); - for (uint32_t i = 0; i < narches; i++) { - fat_arch* arch = (fat_arch*) (obj + sizeof(fat_header) + sizeof(fat_arch) * i); - if (DO_SWAP(should_swap, arch->cputype) == CPU_TYPE_X86_64) { - mach64_offset = (ptrdiff_t) DO_SWAP(should_swap, arch->offset); - break; - } - } - if (mach64_offset == 0) { - printError("could not find any mach64 blobs in file '%1%', continuing...", filename); - return {}; - } - } else if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) { - mach64_offset = 0; - } else { - printError("Object file has unknown magic number '%1%', skipping it...", magic); - return {}; - } - - mach_header_64 * m_header = (mach_header_64 *) (obj + mach64_offset); - - bool should_swap = magic == MH_CIGAM_64; - ptrdiff_t cmd_offset = mach64_offset + sizeof(mach_header_64); - - std::set<std::string> libs; - for (uint32_t i = 0; i < DO_SWAP(should_swap, m_header->ncmds); i++) { - load_command * cmd = (load_command *) (obj + cmd_offset); - switch(DO_SWAP(should_swap, cmd->cmd)) { - case LC_LOAD_UPWARD_DYLIB: - case LC_LOAD_DYLIB: - case LC_REEXPORT_DYLIB: - libs.insert(std::string((char *) cmd + ((dylib_command*) cmd)->dylib.name.offset)); - break; - } - cmd_offset += DO_SWAP(should_swap, cmd->cmdsize); - } - - return libs; -} - -bool isSymlink(const Path & path) -{ - return S_ISLNK(lstat(path).st_mode); -} - -Path resolveSymlink(const Path & path) -{ - auto target = readLink(path); - return target.starts_with("/") - ? target - : concatStrings(dirOf(path), "/", target); -} - -std::set<std::string> resolveTree(const Path & path, PathSet & deps) -{ - std::set<std::string> results; - if (!deps.insert(path).second) return {}; - for (auto & lib : runResolver(path)) { - results.insert(lib); - for (auto & p : resolveTree(lib, deps)) { - results.insert(p); - } - } - return results; -} - -std::set<std::string> getPath(const Path & path) -{ - if (path.starts_with("/dev")) return {}; - - Path cacheFile = resolveCacheFile(path); - if (pathExists(cacheFile)) - return readCacheFile(cacheFile); - - std::set<std::string> deps, paths; - paths.insert(path); - - Path nextPath(path); - while (isSymlink(nextPath)) { - nextPath = resolveSymlink(nextPath); - paths.insert(nextPath); - } - - for (auto & t : resolveTree(nextPath, deps)) - paths.insert(t); - - writeFile(cacheFile, concatStringsSep("\n", paths)); - - return paths; -} - -int main(int argc, char ** argv) -{ - return handleExceptions(argv[0], [&]() { - initNix(); - - struct utsname _uname; - - uname(&_uname); - - auto cacheParentDir = fmt("%1%/dependency-maps", settings.nixStateDir); - - cacheDir = fmt("%1%/%2%-%3%-%4%", cacheParentDir, _uname.machine, _uname.sysname, _uname.release); - - mkdir(cacheParentDir.c_str(), 0755); - mkdir(cacheDir.c_str(), 0755); - - auto store = openStore(); - - StringSet impurePaths; - - if (std::string(argv[1]) == "--test") - impurePaths.insert(argv[2]); - else { - auto drv = store->derivationFromPath(store->parseStorePath(argv[1])); - impurePaths = tokenizeString<StringSet>(getOr(drv.env, "__impureHostDeps", "")); - impurePaths.insert("/usr/lib/libSystem.dylib"); - } - - std::set<std::string> allPaths; - - for (auto & path : impurePaths) - for (auto & p : getPath(path)) - allPaths.insert(p); - - std::cout << "extra-chroot-dirs" << std::endl; - for (auto & path : allPaths) - std::cout << path << std::endl; - std::cout << std::endl; - }); -} |