diff --git a/Makefile b/Makefile index 915dfcd93cb7..f5dd8c211e26 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ ifeq ($(ENABLE_BUILD), yes) makefiles = \ mk/precompiled-headers.mk \ local.mk \ + src/libmain/local.mk \ + src/libcmd/local.mk \ + src/nix/local.mk \ src/libutil/local.mk \ src/libstore/local.mk \ src/libfetchers/local.mk \ @@ -20,9 +23,6 @@ makefiles = \ ifdef HOST_UNIX makefiles += \ - src/libmain/local.mk \ - src/libcmd/local.mk \ - src/nix/local.mk \ src/resolve-system-dependencies/local.mk \ scripts/local.mk \ misc/bash/local.mk \ diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 369fa600441c..3115c4fe265c 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -4,7 +4,9 @@ #include "local-fs-store.hh" #include "derivations.hh" #include "nixexpr.hh" +#ifndef __WIN32 #include "profiles.hh" +#endif #include "repl.hh" #include @@ -235,6 +237,7 @@ void StorePathCommand::run(ref store, StorePaths && storePaths) run(store, *storePaths.begin()); } +#ifndef __WIN32 MixProfile::MixProfile() { addFlag({ @@ -285,6 +288,7 @@ MixDefaultProfile::MixDefaultProfile() { profile = getDefaultProfile(); } +#endif MixEnvironment::MixEnvironment() : ignoreEnvironment(false) { @@ -328,8 +332,10 @@ void MixEnvironment::setEnviron() { if (!keep.empty()) throw UsageError("--keep does not make sense without --ignore-environment"); +#ifndef __WIN32 for (const auto & var : unset) unsetenv(var.c_str()); +#endif } } diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 4a72627ed4db..e87e3eaf30b6 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -294,6 +294,7 @@ static RegisterCommand registerCommand2(std::vector && name) return RegisterCommand(std::move(name), [](){ return make_ref(); }); } +#ifndef __WIN32 struct MixProfile : virtual StoreCommand { std::optional profile; @@ -312,6 +313,7 @@ struct MixDefaultProfile : MixProfile { MixDefaultProfile(); }; +#endif struct MixEnvironment : virtual Args { diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index b87bbbc27c5c..c6ee0d0b2593 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -181,7 +181,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state) v->mkString(arg.s); }, [&](const AutoArgFile & arg) { - v->mkString(readFile(arg.path)); + v->mkString(readFile(arg.path.string())); }, [&](const AutoArgStdin & arg) { v->mkString(readFile(STDIN_FILENO)); diff --git a/src/libcmd/markdown.cc b/src/libcmd/markdown.cc index a4e3c5a77af2..1865714b633b 100644 --- a/src/libcmd/markdown.cc +++ b/src/libcmd/markdown.cc @@ -3,8 +3,8 @@ #include "finally.hh" #include "terminal.hh" -#include #if HAVE_LOWDOWN +#include #include #endif diff --git a/src/libcmd/repl-interacter.cc b/src/libcmd/repl-interacter.cc index 3e34ecdb6ad1..5a4747f1c0ec 100644 --- a/src/libcmd/repl-interacter.cc +++ b/src/libcmd/repl-interacter.cc @@ -137,6 +137,7 @@ static constexpr const char * promptForType(ReplPromptType promptType) bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptType) { +#ifndef __WIN32 struct sigaction act, old; sigset_t savedSignalMask, set; @@ -161,9 +162,12 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT }; setupSignals(); +#endif char * s = readline(promptForType(promptType)); Finally doFree([&]() { free(s); }); +#ifndef __WIN32 restoreSignals(); +#endif if (g_signal_received) { g_signal_received = 0; diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 7cecc60b77cc..2c9e9fbd74fa 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -138,12 +138,14 @@ void runNix(Path program, const Strings & args, auto subprocessEnv = getEnv(); subprocessEnv["NIX_CONFIG"] = globalConfig.toKeyValue(); +#ifndef __WIN32 runProgram2(RunOptions { .program = settings.nixBinDir+ "/" + program, .args = args, .environment = subprocessEnv, .input = input, }); +#endif return; } @@ -228,8 +230,10 @@ ReplExitStatus NixRepl::mainLoop() printMsg(lvlError, e.msg()); } catch (Error & e) { printMsg(lvlError, e.msg()); +#ifndef __WIN32 } catch (Interrupted & e) { printMsg(lvlError, e.msg()); +#endif } // We handled the current input fully, so we should clear it @@ -357,7 +361,9 @@ ProcessLineResult NixRepl::processLine(std::string line) if (line.empty()) return ProcessLineResult::PromptAgain; +#ifndef __WIN32 _isInterrupted = false; +#endif std::string command, arg; @@ -480,6 +486,7 @@ ProcessLineResult NixRepl::processLine(std::string line) reloadFiles(); } +#ifndef __WIN32 else if (command == ":e" || command == ":edit") { Value v; evalString(arg, v); @@ -514,6 +521,7 @@ ProcessLineResult NixRepl::processLine(std::string line) state->resetFileCache(); reloadFiles(); } +#endif else if (command == ":t") { Value v; @@ -568,7 +576,9 @@ ProcessLineResult NixRepl::processLine(std::string line) subs.push_front(state->store); bool foundLog = false; +#ifndef __WIN32 RunPager pager; +#endif for (auto & sub : subs) { auto * logSubP = dynamic_cast(&*sub); if (!logSubP) { diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index 3aa012ee1cc5..9212d6ad0b50 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -406,7 +406,11 @@ class ProgressBar : public Logger } } +#ifndef __WIN32 auto width = getWindowSize().second; +#else + auto width = 0; +#endif if (width <= 0) width = std::numeric_limits::max(); writeToStderr("\r" + filterANSIEscapes(line, false, width) + ANSI_NORMAL + "\e[K"); diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 7bced0aa429a..2feff7c504cb 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -108,7 +108,9 @@ std::string getArg(const std::string & opt, return *i; } +#ifndef __WIN32 static void sigHandler(int signo) { } +#endif void initNix() @@ -121,6 +123,7 @@ void initNix() initLibStore(); +#ifndef __WIN32 startSignalHandlerThread(); /* Reset SIGCHLD to its default. */ @@ -135,6 +138,7 @@ void initNix() /* Install a dummy SIGUSR1 handler for use with pthread_kill(). */ act.sa_handler = sigHandler; if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1"); +#endif #if __APPLE__ /* HACK: on darwin, we need can’t use sigprocmask with SIGWINCH. @@ -156,21 +160,26 @@ void initNix() if (sigaction(SIGTRAP, &act, 0)) throw SysError("handling SIGTRAP"); #endif +#ifndef __WIN32 /* Register a SIGSEGV handler to detect stack overflows. Why not initLibExpr()? initGC() is essentially that, but detectStackOverflow is not an instance of the init function concept, as it may have to be invoked more than once per process. */ detectStackOverflow(); +#endif /* There is no privacy in the Nix system ;-) At least not for now. In particular, store objects should be readable by everybody. */ umask(0022); +#ifndef __WIN32 /* Initialise the PRNG. */ struct timeval tv; gettimeofday(&tv, 0); srandom(tv.tv_usec); +#endif + } @@ -308,7 +317,9 @@ void printVersion(const std::string & programName) void showManPage(const std::string & name) { restoreProcessContext(); +#ifndef __WIN32 setenv("MANPATH", settings.nixManDir.c_str(), 1); +#endif execlp("man", "man", name.c_str(), nullptr); throw SysError("command 'man %1%' failed", name.c_str()); } @@ -329,7 +340,9 @@ int handleExceptions(const std::string & programName, std::function fun) condition is discharged before we reach printMsg() below, since otherwise it will throw an (uncaught) exception. */ +#ifndef __WIN32 setInterruptThrown(); +#endif throw; } } catch (Exit & e) { @@ -352,7 +365,7 @@ int handleExceptions(const std::string & programName, std::function fun) return 0; } - +#ifndef __WIN32 RunPager::RunPager() { if (!isatty(STDOUT_FILENO)) return; @@ -398,6 +411,7 @@ RunPager::~RunPager() ignoreException(); } } +#endif PrintFreed::~PrintFreed() diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 99c3dffab300..afe560f60fc8 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -1,7 +1,9 @@ #pragma once ///@file +#ifndef __WIN32 #include "processes.hh" +#endif #include "args.hh" #include "args/root.hh" #include "common-args.hh" @@ -82,6 +84,7 @@ void showManPage(const std::string & name); * terminal and $PAGER is set. Standard output is redirected to the * pager. */ +#ifndef __WIN32 class RunPager { public: @@ -92,6 +95,7 @@ private: Pid pid; int std_out; }; +#endif extern volatile ::sig_atomic_t blockInt; @@ -112,6 +116,7 @@ struct PrintFreed }; +#ifndef __WIN32 /** * Install a SIGSEGV handler to detect stack overflows. */ @@ -141,5 +146,6 @@ extern std::function stackOverflowHandler; * logger. Exits the process immediately after. */ void defaultStackOverflowHandler(siginfo_t * info, void * ctx); +#endif } diff --git a/src/libmain/stack.cc b/src/libmain/stack.cc index 10f71c1dcadd..6edfb831b667 100644 --- a/src/libmain/stack.cc +++ b/src/libmain/stack.cc @@ -10,7 +10,7 @@ namespace nix { - +#ifndef __WIN32 static void sigsegvHandler(int signo, siginfo_t * info, void * ctx) { /* Detect stack overflows by comparing the faulting address with @@ -73,5 +73,6 @@ void defaultStackOverflowHandler(siginfo_t * info, void * ctx) { [[gnu::unused]] auto res = write(2, msg, strlen(msg)); _exit(1); // maybe abort instead? } +#endif } diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index a372e4b1c7f2..512f2e93538e 100644 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -286,8 +286,10 @@ static void main_nix_build(int argc, char * * argv) left = {"default.nix"}; } +#ifndef __WIN32 if (runEnv) setenv("IN_NIX_SHELL", pure ? "pure" : "impure", 1); +#endif PackageInfos drvs; @@ -571,8 +573,10 @@ static void main_nix_build(int argc, char * * argv) "BASH=%5%; " "set +e; " R"s([ -n "$PS1" -a -z "$NIX_SHELL_PRESERVE_PROMPT" ] && )s" + +#ifndef __WIN32 (getuid() == 0 ? R"s(PS1='\n\[\033[1;31m\][nix-shell:\w]\$\[\033[0m\] '; )s" : R"s(PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s") + +#endif "if [ \"$(type -t runHook)\" = function ]; then runHook shellHook; fi; " "unset NIX_ENFORCE_PURITY; " "shopt -u nullglob; " diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc index 48553fa31d09..17c6485d5dc3 100644 --- a/src/nix-channel/nix-channel.cc +++ b/src/nix-channel/nix-channel.cc @@ -1,4 +1,6 @@ +#ifndef __WIN32 #include "profiles.hh" +#endif #include "shared.hh" #include "globals.hh" #include "filetransfer.hh" diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index 86e6f008db7f..1e17282254ff 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -168,7 +168,7 @@ static int main_nix_instantiate(int argc, char * * argv) for (auto & i : files) { auto p = state->findFile(i); if (auto fn = p.getPhysicalPath()) - std::cout << fn->native() << std::endl; + std::cout << fn->string() << std::endl; else throw Error("'%s' has no physical path", p); } diff --git a/src/nix/build.cc b/src/nix/build.cc index 479100186597..b0a7e47d9147 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -65,7 +65,10 @@ static void createOutLinks(const Path& outLink, const std::vector +# include +#endif + using namespace nix; struct MixCat : virtual Args @@ -15,7 +21,15 @@ struct MixCat : virtual Args if (st.type != SourceAccessor::Type::tRegular) throw Error("path '%1%' is not a regular file", path); stopProgressBar(); - writeFull(STDOUT_FILENO, accessor->readFile(CanonPath(path))); + + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + writeFull(standard_out, accessor->readFile(CanonPath(path))); } }; diff --git a/src/nix/daemon.cc b/src/nix/daemon.cc index 8afcbe98282e..b2a41d7e8132 100644 --- a/src/nix/daemon.cc +++ b/src/nix/daemon.cc @@ -1,5 +1,7 @@ ///@file +#ifndef __WIN32 + #include "signals.hh" #include "unix-domain-socket.hh" #include "command.hh" @@ -586,3 +588,5 @@ struct CmdDaemon : StoreCommand }; static auto rCmdDaemon = registerCommand2({"daemon"}); + +#endif diff --git a/src/nix/develop.cc b/src/nix/develop.cc index c1842f2d57aa..4d22ad59e06c 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -287,7 +287,10 @@ static StorePath getDerivationEnvironment(ref store, ref evalStore throw Error("get-env.sh failed to produce an environment"); } -struct Common : InstallableCommand, MixProfile +struct Common : InstallableCommand +#ifndef __WIN32 +, MixProfile +#endif { std::set ignoreVars{ "BASHOPTS", @@ -473,7 +476,9 @@ struct Common : InstallableCommand, MixProfile auto strPath = store->printStorePath(shellOutPath); +#ifndef __WIN32 updateProfile(shellOutPath); +#endif debug("reading environment file '%s'", strPath); @@ -603,7 +608,9 @@ struct CmdDevelop : Common, MixEnvironment setEnviron(); // prevent garbage collection until shell exits +#ifndef __WIN32 setenv("NIX_GCROOT", gcroot.c_str(), 1); +#endif Path shell = "bash"; @@ -648,6 +655,7 @@ struct CmdDevelop : Common, MixEnvironment // Override SHELL with the one chosen for this environment. // This is to make sure the system shell doesn't leak into the build environment. +#ifndef __WIN32 setenv("SHELL", shell.c_str(), 1); // If running a phase or single command, don't want an interactive shell running after @@ -670,6 +678,7 @@ struct CmdDevelop : Common, MixEnvironment } runProgramInStore(store, UseSearchPath::Use, shell, args, buildEnvironment.getSystem()); +#endif } }; diff --git a/src/nix/dump-path.cc b/src/nix/dump-path.cc index 0850d4c1cdb5..fb7eeec769fc 100644 --- a/src/nix/dump-path.cc +++ b/src/nix/dump-path.cc @@ -2,6 +2,12 @@ #include "store-api.hh" #include "archive.hh" +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#endif + using namespace nix; struct CmdDumpPath : StorePathCommand @@ -20,7 +26,14 @@ struct CmdDumpPath : StorePathCommand void run(ref store, const StorePath & storePath) override { - FdSink sink(STDOUT_FILENO); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + FdSink sink(standard_out); store->narFromPath(storePath, sink); sink.flush(); } @@ -55,7 +68,14 @@ struct CmdDumpPath2 : Command void run() override { - FdSink sink(STDOUT_FILENO); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + FdSink sink(standard_out); dumpPath(path, sink); sink.flush(); } diff --git a/src/nix/eval.cc b/src/nix/eval.cc index 088be3b17827..a469d20f35e3 100644 --- a/src/nix/eval.cc +++ b/src/nix/eval.cc @@ -9,6 +9,12 @@ #include +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#endif + using namespace nix; struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption @@ -87,7 +93,11 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption // FIXME: disallow strings with contexts? writeFile(path, v.string_view()); else if (v.type() == nAttrs) { - if (mkdir(path.c_str(), 0777) == -1) + if (mkdir(path.c_str() +#ifndef __WIN32 + , 0777 +#endif + ) == -1) throw SysError("creating directory '%s'", path); for (auto & attr : *v.attrs) { std::string_view name = state->symbols[attr.name]; @@ -112,7 +122,14 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption else if (raw) { stopProgressBar(); - writeFull(STDOUT_FILENO, *state->coerceToString(noPos, *v, context, "while generating the eval command output")); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + writeFull(standard_out, *state->coerceToString(noPos, *v, context, "while generating the eval command output")); } else if (json) { diff --git a/src/nix/flake.cc b/src/nix/flake.cc index a846f6371149..983a92f5775f 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -891,6 +891,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand } else writeFile(to2, contents); } +#ifndef __WIN32 else if (S_ISLNK(st.st_mode)) { auto target = readLink(from2); if (pathExists(to2)) { @@ -904,6 +905,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand } else createSymlink(target, to2); } +#endif else throw Error("file '%s' has unsupported type", from2); changedFiles.push_back(to2); @@ -913,11 +915,13 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand copyDir(templateDir, flakeDir); +#ifndef __WIN32 if (!changedFiles.empty() && pathExists(flakeDir + "/.git")) { Strings args = { "-C", flakeDir, "add", "--intent-to-add", "--force", "--" }; for (auto & s : changedFiles) args.push_back(s); runProgram("git", true, args); } +#endif auto welcomeText = cursor->maybeGetAttr("welcomeText"); if (welcomeText) { notice("\n"); diff --git a/src/nix/fmt.cc b/src/nix/fmt.cc index 059904150f30..bd533caae47f 100644 --- a/src/nix/fmt.cc +++ b/src/nix/fmt.cc @@ -1,3 +1,5 @@ +#ifndef __WIN32 + #include "command.hh" #include "installable-value.hh" #include "run.hh" @@ -54,3 +56,5 @@ struct CmdFmt : SourceExprCommand { }; static auto r2 = registerCommand("fmt"); + +#endif diff --git a/src/nix/local.mk b/src/nix/local.mk index 55544b5643b2..176fc25c3cd0 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -4,6 +4,11 @@ nix_DIR := $(d) nix_SOURCES := \ $(wildcard $(d)/*.cc) \ + $(wildcard src/nix-instantiate/*.cc) \ + $(wildcard src/nix-build/*.cc) + +ifdef HOST_UNIX +nix_SOURCES += \ $(wildcard src/build-remote/*.cc) \ $(wildcard src/nix-build/*.cc) \ $(wildcard src/nix-channel/*.cc) \ @@ -11,8 +16,8 @@ nix_SOURCES := \ $(wildcard src/nix-copy-closure/*.cc) \ $(wildcard src/nix-daemon/*.cc) \ $(wildcard src/nix-env/*.cc) \ - $(wildcard src/nix-instantiate/*.cc) \ - $(wildcard src/nix-store/*.cc) \ + $(wildcard src/nix-store/*.cc) +endif nix_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers) $(INCLUDE_libexpr) -I src/libmain -I src/libcmd -I doc/manual diff --git a/src/nix/log.cc b/src/nix/log.cc index 9a9bd30f9619..4c7185831ec3 100644 --- a/src/nix/log.cc +++ b/src/nix/log.cc @@ -5,6 +5,12 @@ #include "log-store.hh" #include "progress-bar.hh" +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#endif + using namespace nix; struct CmdLog : InstallableCommand @@ -44,7 +50,9 @@ struct CmdLog : InstallableCommand }, b.path.raw()); auto path = resolveDerivedPath(*store, *oneUp); +#ifndef __WIN32 RunPager pager; +#endif for (auto & sub : subs) { auto * logSubP = dynamic_cast(&*sub); if (!logSubP) { @@ -57,7 +65,14 @@ struct CmdLog : InstallableCommand if (!log) continue; stopProgressBar(); printInfo("got build log for '%s' from '%s'", installable->what(), logSub.getUri()); - writeFull(STDOUT_FILENO, *log); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + writeFull(standard_out, *log); return; } diff --git a/src/nix/main.cc b/src/nix/main.cc index b648b02c40b3..a078aa31d373 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -17,10 +17,12 @@ #include "memory-input-accessor.hh" #include +#ifndef __WIN32 #include #include #include #include +#endif #include #if __linux__ @@ -29,9 +31,11 @@ #include +#ifndef __WIN32 extern std::string chrootHelperName; void chrootHelper(int argc, char * * argv); +#endif namespace nix { @@ -56,6 +60,7 @@ static bool haveProxyEnvironmentVariables() /* Check if we have a non-loopback/link-local network interface. */ static bool haveInternet() { +#ifndef __WIN32 struct ifaddrs * addrs; if (getifaddrs(&addrs)) @@ -79,6 +84,9 @@ static bool haveInternet() if (haveProxyEnvironmentVariables()) return true; return false; +#else + return true; +#endif } std::string programPath; @@ -265,7 +273,9 @@ static void showHelp(std::vector subcommand, NixArgs & toplevel) auto markdown = state.forceString(*attr->value, noPos, "while evaluating the lowdown help text"); +#ifndef __WIN32 RunPager pager; +#endif std::cout << renderMarkdownToTerminal(markdown) << "\n"; } @@ -341,10 +351,12 @@ void mainWrapped(int argc, char * * argv) /* The chroot helper needs to be run before any threads have been started. */ +#ifndef __WIN32 if (argc > 0 && argv[0] == chrootHelperName) { chrootHelper(argc, argv); return; } +#endif initNix(); initGC(); @@ -363,6 +375,9 @@ void mainWrapped(int argc, char * * argv) programPath = argv[0]; auto programName = std::string(baseNameOf(programPath)); + auto extensionPos = programName.find_last_of("."); + if (extensionPos != std::string::npos) + programName.erase(extensionPos); if (argc > 1 && std::string_view(argv[1]) == "__build-remote") { programName = "build-remote"; @@ -522,9 +537,11 @@ void mainWrapped(int argc, char * * argv) int main(int argc, char * * argv) { +#ifndef __WIN32 // Increase the default stack size for the evaluator and for // libstdc++'s std::regex. nix::setStackSize(64 * 1024 * 1024); +#endif return nix::handleExceptions(argv[0], [&]() { nix::mainWrapped(argc, argv); diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index fabec5d88237..21ecf08d8081 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -94,7 +94,7 @@ std::tuple prefetchFile( if (executable) mode = 0700; - AutoCloseFD fd = open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, mode); + AutoCloseFD fd = toDesc(open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, mode)); if (!fd) throw SysError("creating temporary file '%s'", tmpFile); FdSink sink(fd.get()); diff --git a/src/nix/profile.cc b/src/nix/profile.cc index a5a40e4f66c9..56c8c9a3f1a9 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -1,3 +1,5 @@ +#ifndef __WIN32 + #include "command.hh" #include "installable-flake.hh" #include "common-args.hh" @@ -999,3 +1001,5 @@ struct CmdProfile : NixMultiCommand }; static auto rCmdProfile = registerCommand("profile"); + +#endif diff --git a/src/nix/run.cc b/src/nix/run.cc index e868376790fb..3153e7f14c43 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -1,3 +1,5 @@ +#ifndef __WIN32 + #include "current-process.hh" #include "run.hh" #include "command-installable-value.hh" @@ -287,3 +289,5 @@ void chrootHelper(int argc, char * * argv) throw Error("mounting the Nix store on '%s' is not supported on this platform", storeDir); #endif } + +#endif \ No newline at end of file diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc index dfef44869315..192e797d68f3 100644 --- a/src/nix/sigs.cc +++ b/src/nix/sigs.cc @@ -7,6 +7,12 @@ #include +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#endif + using namespace nix; struct CmdCopySigs : StorePathsCommand @@ -177,7 +183,14 @@ struct CmdKeyGenerateSecret : Command throw UsageError("required argument '--key-name' is missing"); stopProgressBar(); - writeFull(STDOUT_FILENO, SecretKey::generate(*keyName).to_string()); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + writeFull(standard_out, SecretKey::generate(*keyName).to_string()); } }; @@ -199,7 +212,14 @@ struct CmdKeyConvertSecretToPublic : Command { SecretKey secretKey(drainFD(STDIN_FILENO)); stopProgressBar(); - writeFull(STDOUT_FILENO, secretKey.toPublicKey().to_string()); + Descriptor standard_out = +#ifdef _WIN32 + GetStdHandle(STD_OUTPUT_HANDLE) +#else + STDOUT_FILENO +#endif + ; + writeFull(standard_out, secretKey.toPublicKey().to_string()); } }; diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index 4c7a74e16f19..c0299301103d 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -1,3 +1,5 @@ +#ifndef __WIN32 + #include "processes.hh" #include "command.hh" #include "common-args.hh" @@ -158,3 +160,5 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand }; static auto rCmdUpgradeNix = registerCommand("upgrade-nix"); + +#endif diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index e299585ff88e..aafc9cdceaf7 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -291,7 +291,9 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions } }; +#ifndef __WIN32 RunPager pager; +#endif try { if (!precise) { logger->cout("%s", store->printStorePath(graph.at(packagePath).path));