aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc14
-rw-r--r--src/nix/command.hh8
-rw-r--r--src/nix/eval.cc2
-rw-r--r--src/nix/flake-template.nix2
-rw-r--r--src/nix/installables.cc33
-rw-r--r--src/nix/shell.cc6
6 files changed, 48 insertions, 17 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 06655b8e2..4520309cd 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -1,6 +1,7 @@
#include "command.hh"
#include "store-api.hh"
#include "derivations.hh"
+#include "nixexpr.hh"
#include "profiles.hh"
namespace nix {
@@ -82,6 +83,19 @@ void StorePathCommand::run(ref<Store> store)
run(store, *storePaths.begin());
}
+Strings editorFor(const Pos & pos)
+{
+ auto editor = getEnv("EDITOR", "cat");
+ auto args = tokenizeString<Strings>(editor);
+ if (pos.line > 0 && (
+ editor.find("emacs") != std::string::npos ||
+ editor.find("nano") != std::string::npos ||
+ editor.find("vim") != std::string::npos))
+ args.push_back(fmt("+%d", pos.line));
+ args.push_back(pos.file);
+ return args;
+}
+
MixProfile::MixProfile()
{
mkFlag()
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 52fb4e1f5..16f8997dd 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -11,6 +11,7 @@ namespace nix {
extern std::string programPath;
class EvalState;
+struct Pos;
class Store;
namespace flake {
@@ -55,6 +56,7 @@ struct MixFlakeOptions : virtual Args
struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
{
std::optional<Path> file;
+ std::optional<std::string> expr;
SourceExprCommand();
@@ -105,7 +107,7 @@ struct InstallableCommand : virtual Args, SourceExprCommand
private:
- std::string _installable{"."};
+ std::string _installable{""};
};
/* A command that operates on zero or more store paths. */
@@ -175,6 +177,10 @@ PathSet toDerivations(ref<Store> store,
std::vector<std::shared_ptr<Installable>> installables,
bool useDeriver = false);
+/* Helper function to generate args that invoke $EDITOR on
+ filename:lineno. */
+Strings editorFor(const Pos & pos);
+
struct MixProfile : virtual Args, virtual StoreCommand
{
std::optional<Path> profile;
diff --git a/src/nix/eval.cc b/src/nix/eval.cc
index 276fdf003..a991ee608 100644
--- a/src/nix/eval.cc
+++ b/src/nix/eval.cc
@@ -28,7 +28,7 @@ struct CmdEval : MixJSON, InstallableCommand
return {
Example{
"To evaluate a Nix expression given on the command line:",
- "nix eval '(1 + 2)'"
+ "nix eval --expr '1 + 2'"
},
Example{
"To evaluate a Nix expression from a file or URI:",
diff --git a/src/nix/flake-template.nix b/src/nix/flake-template.nix
index eb8eb14fc..321961013 100644
--- a/src/nix/flake-template.nix
+++ b/src/nix/flake-template.nix
@@ -5,7 +5,7 @@
outputs = { self, nixpkgs }: {
- packages.x86_64-linux.hello = nixpkgs.packages.x86_64-linux.hello;
+ packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
};
}
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 671cf513a..3e0fe2606 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -51,8 +51,14 @@ SourceExprCommand::SourceExprCommand()
.shortName('f')
.longName("file")
.label("file")
- .description("evaluate a set of attributes from FILE (deprecated)")
+ .description("evaluate attributes from FILE")
.dest(&file);
+
+ mkFlag()
+ .longName("expr")
+ .label("expr")
+ .description("evaluate attributes from EXPR")
+ .dest(&expr);
}
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
@@ -378,19 +384,25 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
{
std::vector<std::shared_ptr<Installable>> result;
- if (file) {
+ if (file || expr) {
+ if (file && expr)
+ throw UsageError("'--file' and '--expr' are exclusive");
+
// FIXME: backward compatibility hack
- evalSettings.pureEval = false;
+ if (file) evalSettings.pureEval = false;
auto state = getEvalState();
auto vFile = state->allocValue();
- state->evalFile(lookupFileArg(*state, *file), *vFile);
- if (ss.empty())
- ss = {""};
+ if (file)
+ state->evalFile(lookupFileArg(*state, *file), *vFile);
+ else {
+ auto e = state->parseExprFromString(*expr, absPath("."));
+ state->eval(e, *vFile);
+ }
for (auto & s : ss)
- result.push_back(std::make_shared<InstallableAttrPath>(*this, vFile, s));
+ result.push_back(std::make_shared<InstallableAttrPath>(*this, vFile, s == "." ? "" : s));
} else {
@@ -407,10 +419,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
size_t hash;
std::optional<Path> storePath;
- if (s.compare(0, 1, "(") == 0)
- result.push_back(std::make_shared<InstallableExpr>(*this, s));
-
- else if (hasPrefix(s, "nixpkgs.")) {
+ if (hasPrefix(s, "nixpkgs.")) {
bool static warned;
warnOnce(warned, "the syntax 'nixpkgs.<attr>' is deprecated; use 'nixpkgs:<attr>' instead");
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef("nixpkgs"),
@@ -532,7 +541,7 @@ PathSet toDerivations(ref<Store> store,
void InstallablesCommand::prepare()
{
- if (_installables.empty() && !file && useDefaultInstallables())
+ if (_installables.empty() && useDefaultInstallables())
// FIXME: commands like "nix install" should not have a
// default, probably.
_installables.push_back(".");
diff --git a/src/nix/shell.cc b/src/nix/shell.cc
index 5e13604bc..2c5142518 100644
--- a/src/nix/shell.cc
+++ b/src/nix/shell.cc
@@ -29,6 +29,8 @@ BuildEnvironment readEnvironment(const Path & path)
std::set<std::string> exported;
+ debug("reading environment file '%s'", path);
+
auto file = readFile(path);
auto pos = file.cbegin();
@@ -41,10 +43,10 @@ BuildEnvironment readEnvironment(const Path & path)
R"re((?:="((?:[^"\\]|\\.)*)")?\n)re");
static std::string simpleStringRegex =
- R"re((?:[a-zA-Z0-9_/:\.\-1\+]*))re";
+ R"re((?:[a-zA-Z0-9_/:\.\-\+=]*))re";
static std::string quotedStringRegex =
- R"re((?:\$?'[^']*'))re";
+ R"re((?:\$?'(?:[^'\\]|\\[abeEfnrtv\\'"?])*'))re";
static std::string arrayRegex =
R"re((?:\(( *\[[^\]]+\]="(?:[^"\\]|\\.)*")*\)))re";