diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/eval.cc | 1 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 3 | ||||
-rw-r--r-- | src/libexpr/function-trace.hh | 3 | ||||
-rw-r--r-- | src/libutil/args.cc | 13 | ||||
-rw-r--r-- | src/libutil/args.hh | 4 | ||||
-rw-r--r-- | src/nix/command.cc | 14 | ||||
-rw-r--r-- | src/nix/command.hh | 8 | ||||
-rw-r--r-- | src/nix/eval.cc | 2 | ||||
-rw-r--r-- | src/nix/flake-template.nix | 2 | ||||
-rw-r--r-- | src/nix/installables.cc | 33 | ||||
-rw-r--r-- | src/nix/shell.cc | 6 |
11 files changed, 52 insertions, 37 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 66683e936..0b3f75d60 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -7,6 +7,7 @@ #include "eval-inline.hh" #include "download.hh" #include "json.hh" +#include "function-trace.hh" #include "flake/flake.hh" #include <algorithm> diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 5469a8ab2..0ce1cda3c 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -4,13 +4,12 @@ #include "value.hh" #include "nixexpr.hh" #include "symbol-table.hh" -#include "hash.hh" #include "config.hh" -#include "function-trace.hh" #include <map> #include <optional> #include <unordered_map> +#include <mutex> namespace nix { diff --git a/src/libexpr/function-trace.hh b/src/libexpr/function-trace.hh index 8b0ec848d..2c39b7430 100644 --- a/src/libexpr/function-trace.hh +++ b/src/libexpr/function-trace.hh @@ -1,7 +1,8 @@ #pragma once #include "eval.hh" -#include <sys/time.h> + +#include <chrono> namespace nix { diff --git a/src/libutil/args.cc b/src/libutil/args.cc index ad7a268fc..ba15ea571 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -178,19 +178,6 @@ Strings argvToStrings(int argc, char * * argv) return args; } -Strings editorFor(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; -} - std::string renderLabels(const Strings & labels) { std::string res; diff --git a/src/libutil/args.hh b/src/libutil/args.hh index 59d427ee6..b960a55a8 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -5,7 +5,6 @@ #include <memory> #include "util.hh" -#include "nixexpr.hh" namespace nix { @@ -242,9 +241,6 @@ public: Strings argvToStrings(int argc, char * * argv); -/* Helper function to generate args that invoke $EDITOR on filename:lineno */ -Strings editorFor(Pos pos); - /* Helper function for rendering argument labels. */ std::string renderLabels(const Strings & labels); 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"; |