Make "nix repl" build
This commit is contained in:
parent
c31000bc93
commit
921a2aeb05
|
@ -73,7 +73,8 @@ let
|
||||||
buildInputs =
|
buildInputs =
|
||||||
[ curl
|
[ curl
|
||||||
bzip2 xz brotli
|
bzip2 xz brotli
|
||||||
openssl pkgconfig sqlite boehmgc
|
openssl pkgconfig sqlite boehmgc readline
|
||||||
|
|
||||||
]
|
]
|
||||||
++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium
|
++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium
|
||||||
++ lib.optional (stdenv.isLinux || stdenv.isDarwin)
|
++ lib.optional (stdenv.isLinux || stdenv.isDarwin)
|
||||||
|
|
|
@ -16,6 +16,7 @@ with import <nixpkgs> {};
|
||||||
customMemoryManagement = false;
|
customMemoryManagement = false;
|
||||||
})
|
})
|
||||||
autoreconfHook
|
autoreconfHook
|
||||||
|
readline
|
||||||
];
|
];
|
||||||
|
|
||||||
configureFlags =
|
configureFlags =
|
||||||
|
|
|
@ -6,4 +6,6 @@ nix_SOURCES := $(wildcard $(d)/*.cc)
|
||||||
|
|
||||||
nix_LIBS = libexpr libmain libstore libutil libformat
|
nix_LIBS = libexpr libmain libstore libutil libformat
|
||||||
|
|
||||||
|
nix_LDFLAGS = -lreadline
|
||||||
|
|
||||||
$(eval $(call install-symlink, nix, $(bindir)/nix-hash))
|
$(eval $(call install-symlink, nix, $(bindir)/nix-hash))
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#include <nix/config.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -17,9 +15,11 @@
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "affinity.hh"
|
#include "affinity.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
|
#include "command.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
#define ESC_RED "\033[31m"
|
#define ESC_RED "\033[31m"
|
||||||
#define ESC_GRE "\033[32m"
|
#define ESC_GRE "\033[32m"
|
||||||
|
@ -49,6 +49,7 @@ struct NixRepl
|
||||||
StringSet::iterator curCompletion;
|
StringSet::iterator curCompletion;
|
||||||
|
|
||||||
NixRepl(const Strings & searchPath, nix::ref<Store> store);
|
NixRepl(const Strings & searchPath, nix::ref<Store> store);
|
||||||
|
~NixRepl();
|
||||||
void mainLoop(const Strings & files);
|
void mainLoop(const Strings & files);
|
||||||
void completePrefix(string prefix);
|
void completePrefix(string prefix);
|
||||||
bool getLine(string & input, const char * prompt);
|
bool getLine(string & input, const char * prompt);
|
||||||
|
@ -119,10 +120,16 @@ NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NixRepl::~NixRepl()
|
||||||
|
{
|
||||||
|
write_history(historyFile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::mainLoop(const Strings & files)
|
void NixRepl::mainLoop(const Strings & files)
|
||||||
{
|
{
|
||||||
string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
||||||
std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;
|
std::cout << "Welcome to Nix version " << nixVersion << ". Type :? for help." << std::endl << std::endl;
|
||||||
|
|
||||||
for (auto & i : files)
|
for (auto & i : files)
|
||||||
loadedFiles.push_back(i);
|
loadedFiles.push_back(i);
|
||||||
|
@ -685,35 +692,30 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CmdRepl : StoreCommand
|
||||||
int main(int argc, char * * argv)
|
|
||||||
{
|
{
|
||||||
return handleExceptions(argv[0], [&]() {
|
Strings files;
|
||||||
initNix();
|
|
||||||
initGC();
|
|
||||||
|
|
||||||
Strings files, searchPath;
|
CmdRepl()
|
||||||
|
{
|
||||||
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
expectArgs("files", &files);
|
||||||
if (*arg == "--version")
|
|
||||||
printVersion("nix-repl");
|
|
||||||
else if (*arg == "--help") {
|
|
||||||
printHelp();
|
|
||||||
// exit with 0 since user asked for help
|
|
||||||
_exit(0);
|
|
||||||
}
|
}
|
||||||
else if (parseSearchPathArg(arg, end, searchPath))
|
|
||||||
;
|
|
||||||
else if (*arg != "" && arg->at(0) == '-')
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
files.push_back(*arg);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
NixRepl repl(searchPath, openStore());
|
std::string name() override { return "repl"; }
|
||||||
|
|
||||||
|
std::string description() override
|
||||||
|
{
|
||||||
|
return "start an interactive environment for evaluating Nix expressions";
|
||||||
|
}
|
||||||
|
|
||||||
|
void run(ref<Store> store) override
|
||||||
|
{
|
||||||
|
// FIXME: pass searchPath
|
||||||
|
NixRepl repl({}, openStore());
|
||||||
repl.mainLoop(files);
|
repl.mainLoop(files);
|
||||||
|
}
|
||||||
write_history(historyFile.c_str());
|
};
|
||||||
});
|
|
||||||
|
static RegisterCommand r1(make_ref<CmdRepl>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue