Compare commits

...
Author SHA1 Message Date
Eelco Dolstra 2d52180455 printError -> printTalkative 2018-03-02 17:31:11 +01:00
Eelco Dolstra 64ea7cc437 Add an 'include' keyword
Inclusion is like importing, except that all variables that in scope
at the 'include' site are in scope of the included file.

Thus, if ./foo.nix contains 'x', then

  let x = 1; in include ./foo.nix

evaluates to 1.

(Note that 'include' has to be a keyword, not a builtin function,
because inclusion takes place within a specific scope. I.e. 'include
./foo.nix' would not be equivalent to 'let f = include; in ... f
./foo.nix ...'.)
2018-03-02 17:12:54 +01:00
Eelco Dolstra 939cf4cceb Fix error message 2018-03-02 14:32:00 +01:00
Shea Levy 4a000cbb39 Merge pull request #1927 from dtzWill/fix/fetchgit-HEAD
fetchGit: use "HEAD" as default ref instead of "master"
2018-02-28 18:44:57 -05:00
Will Dietz e89d02bf03 fetchGit: use "HEAD" as default ref 2018-02-28 16:34:34 -06:00
Daiderd Jordan 05cb8e5c5a launchd: enable keepalive for the nix-daemon service
Without this the daemon won't be restarted if the process ever dies, for
example when sending a SIGHUP to reload nix.conf.
2018-02-28 19:58:48 +01:00
Shea Levy 14ca85688c Actually fix nixDataDir in non-canonical path 2018-02-28 06:19:40 -05:00
Eelco Dolstra 8a5da93841 Merge pull request #1912 from dezgeg/replacestrings-take-2
libexpr: Fix prim_replaceStrings() to work on an empty source string, take 2
2018-02-27 12:53:19 +01:00
Tuomas Tynkkynen 77e9e1ed91 libexpr: Fix prim_replaceStrings() to work on an empty source string
Otherwise, running e.g.

nix-instantiate --eval -E --strict 'builtins.replaceStrings [""] ["X"] "abc"'

would just hang in an infinite loop.

Found by afl-fuzz.

First attempt of this was reverted in e2d71bd186 because it caused
another infinite loop, which is fixed now and a test added.
2018-02-26 19:49:13 +02:00
Eelco Dolstra 24ec750003 nix run: Fix segfault on macOS
Note that clearenv() is not available on macOS.

Fixes #1907.
2018-02-26 18:29:40 +01:00
Graham Christensen 9432f3fb7d Merge pull request #1901 from veprbl/patch-5
Fix a small typo in the release notes
2018-02-24 10:26:14 -05:00
Graham Christensen ab435463d0 Merge pull request #1903 from primeos/release-notes-2.0-url-fix
doc: Fix a URL in the release notes for Nix 2.0
2018-02-24 10:19:39 -05:00
Michael Weiss bd94e63853 doc: Fix a URL in the release notes for Nix 2.0 2018-02-24 16:07:10 +01:00
Dmitry Kalinkin d9d8a84a96 Fix a small typo in the release notes 2018-02-23 23:45:42 -05:00
Eelco Dolstra 64e486ab63 Fix downloadCached() with a chroot store
E.g.

  nix run --store ~/my-nix -f channel:nixos-17.03 hello -c hello

This problem was mentioned in #1897.
2018-02-23 13:00:42 +01:00
Eelco Dolstra 39b4177500 Fix example in release notes 2018-02-22 17:42:06 +01:00
Eelco Dolstra 2691d51a33 Doh 2018-02-22 17:14:35 +01:00
Eelco Dolstra b6dec2f3ca Release script tweaks 2018-02-22 17:11:17 +01:00
22 changed files with 129 additions and 31 deletions

No files matched your search

+7 -9
View File
@@ -35,14 +35,14 @@
available paths from the installation medium. The replacement is
to use a chroot store as a substituter
(e.g. <literal>--substituters /mnt</literal>), or to build into a
chroot store (e.g. <literal>--store /mnt --substituter /</literal>).</para>
chroot store (e.g. <literal>--store /mnt --substituters /</literal>).</para>
</listitem>
<listitem>
<para>The command <command>nix-push</command> has been removed as
part of the effort to eliminate Nix's dependency on Perl. You can
use <command>nix copy</command> instead, e.g. <literal>nix copy
--to /tmp/my-binary-cache <replaceable>paths…</replaceable></literal></para>
--to file:///tmp/my-binary-cache <replaceable>paths…</replaceable></literal></para>
</listitem>
<listitem>
@@ -323,13 +323,12 @@
<listitem>
<para><command>nix sign-paths</command> signs store
paths. (TODO: add examples)</para>
paths.</para>
</listitem>
<listitem>
<para><command>nix copy-sigs</command> copies signatures from
one store to another. (TODO: add examples and
tests)</para>
one store to another.</para>
</listitem>
<listitem>
@@ -460,7 +459,7 @@
secret keys specified by the <option>secret-key-files</option>
store option. Secret/public key pairs can be generated using
<command>nix-store
--generate-binary-cache-key</command>. (TODO: rename)</para>
--generate-binary-cache-key</command>.</para>
<para>In addition, locally-built store paths are marked as
“ultimately trusted”, but this bit is not propagated when
@@ -537,7 +536,7 @@
xlink:href="https://github.com/NixOS/nix/commit/8bdf83f936adae6f2c907a6d2541e80d4120f051">no
longer</link> a fatal error if build rounds produce different
output. Also, a hook named <option>diff-hook</option> is <link
xlink:href="https://github.com/NixOS/nix/commit/9a313469a4bdea2d1e8df24d16289dc2a172a169w">provided</link>
xlink:href="https://github.com/NixOS/nix/commit/9a313469a4bdea2d1e8df24d16289dc2a172a169">provided</link>
to allow you to run tools such as <command>diffoscope</command>
when build rounds produce different output.</para>
</listitem>
@@ -723,8 +722,7 @@ configureFlags = "--prefix=${placeholder "out"} --includedir=${placeholder "dev"
will cause the <envar>configureFlags</envar> environment variable
to contain the actual store paths corresponding to the
<literal>out</literal> and <literal>dev</literal> outputs. TODO:
add docs.</para>
<literal>out</literal> and <literal>dev</literal> outputs.</para>
</listitem>
</itemizedlist>
+9 -4
View File
@@ -6,6 +6,7 @@ use Data::Dumper;
use File::Basename;
use File::Path;
use File::Slurp;
use File::Copy;
use JSON::PP;
use LWP::UserAgent;
@@ -54,7 +55,7 @@ sub downloadFile {
my $buildInfo = decode_json(fetch("$evalUrl/job/$jobName", 'application/json'));
my $srcFile = $buildInfo->{buildproducts}->{$productNr}->{path} or die;
my $srcFile = $buildInfo->{buildproducts}->{$productNr}->{path} or die "job '$jobName' lacks product $productNr\n";
$dstName //= basename($srcFile);
my $dstFile = "$releaseDir/" . $dstName;
@@ -78,9 +79,8 @@ sub downloadFile {
return ($dstFile, $sha256_expected);
}
downloadFile("tarball", "2"); # PDF
downloadFile("tarball", "3"); # .tar.bz2
my ($tarball, $tarballHash) = downloadFile("tarball", "4"); # .tar.xz
downloadFile("tarball", "2"); # .tar.bz2
my ($tarball, $tarballHash) = downloadFile("tarball", "3"); # .tar.xz
my ($tarball_i686_linux, $tarball_i686_linux_hash) = downloadFile("binaryTarball.i686-linux", "1");
my ($tarball_x86_64_linux, $tarball_x86_64_linux_hash) = downloadFile("binaryTarball.x86_64-linux", "1");
my ($tarball_aarch64_linux, $tarball_aarch64_linux_hash) = downloadFile("binaryTarball.aarch64-linux", "1");
@@ -152,4 +152,9 @@ write_file("$siteDir/nix-release.tt",
system("cd $siteDir && nix-shell --run 'make nix/install nix/install.sig'") == 0 or die;
copy("$siteDir/nix/install", "$siteDir/nix/install-$version") or die;
copy("$siteDir/nix/install.sig", "$siteDir/nix/install-$version.sig") or die;
system("cd $siteDir && git add nix/install-$version nix/install-$version.sig") == 0 or die;
system("cd $siteDir && git commit -a -m 'Nix $version released'") == 0 or die;
@@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nixos.nix-daemon</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>Program</key>
+2 -2
View File
@@ -74,10 +74,10 @@ static void createLinks(const Path & srcDir, const Path & dstDir, int priority)
auto prevPriority = priorities[dstFile];
if (prevPriority == priority)
throw Error(format(
"Packages '%1%' and '%2%' have the same priority '%3%'"
"packages '%1%' and '%2%' have the same priority %3%; "
"use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' "
"to change the priority of one of the conflicting packages"
" ('0' being the highest priority)"
" (0 being the highest priority)"
) % srcFile % target % priority);
if (prevPriority < priority)
continue;
+18 -1
View File
@@ -313,7 +313,7 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
for (auto & i : _searchPath) addToSearchPath(i);
for (auto & i : paths) addToSearchPath(i);
}
addToSearchPath("nix=" + canonPath(settings.nixDataDir + "/nix/corepkgs"));
addToSearchPath("nix=" + canonPath(settings.nixDataDir + "/nix/corepkgs", true));
if (settings.restrictEval || settings.pureEval) {
allowedPaths = PathSet();
@@ -1386,6 +1386,23 @@ void ExprPos::eval(EvalState & state, Env & env, Value & v)
}
void ExprInclude::eval(EvalState & state, Env & env, Value & v)
{
Value vPath;
path->eval(state, env, vPath);
PathSet context;
auto realPath = state.checkSourcePath(
state.toRealPath(state.coerceToPath(pos, vPath, context), context));
printTalkative("including file '%1%'", realPath);
auto e = state.parseExprFromFile(resolveExprPath(realPath), *staticEnv);
e->eval(state, env, v);
}
void EvalState::forceValueDeep(Value & v)
{
std::set<const Value *> seen;
+1
View File
@@ -109,6 +109,7 @@ in { return IN; }
rec { return REC; }
inherit { return INHERIT; }
or { return OR_KW; }
include { return INCLUDE; }
\.\.\. { return ELLIPSIS; }
\=\= { return EQ; }
+23
View File
@@ -191,6 +191,11 @@ void ExprPos::show(std::ostream & str)
str << "__curPos";
}
void ExprInclude::show(std::ostream & str)
{
str << "(include " << *path << ")";
}
std::ostream & operator << (std::ostream & str, const Pos & pos)
{
@@ -402,6 +407,24 @@ void ExprPos::bindVars(const StaticEnv & env)
{
}
void ExprInclude::bindVars(const StaticEnv & env)
{
path->bindVars(env);
/* Copy the static environment so that ExprInclude::eval() can
pass it to parseExprFromFile(). FIXME: if there are many uses
of 'include' in the same scope, we should cache this. */
const StaticEnv * srcEnv = &env;
StaticEnv * * dstEnv = &staticEnv;
while (srcEnv) {
*dstEnv = new StaticEnv(*srcEnv);
srcEnv = srcEnv->up;
dstEnv = (StaticEnv * *) &(*dstEnv)->up;
}
}
/* Storing function names. */
+12 -3
View File
@@ -86,9 +86,9 @@ struct Expr
std::ostream & operator << (std::ostream & str, Expr & e);
#define COMMON_METHODS \
void show(std::ostream & str); \
void eval(EvalState & state, Env & env, Value & v); \
void bindVars(const StaticEnv & env);
void show(std::ostream & str) override; \
void eval(EvalState & state, Env & env, Value & v) override; \
void bindVars(const StaticEnv & env) override;
struct ExprInt : Expr
{
@@ -326,6 +326,15 @@ struct ExprPos : Expr
COMMON_METHODS
};
struct ExprInclude : Expr
{
Pos pos;
Expr * path;
StaticEnv * staticEnv;
ExprInclude(const Pos & pos, Expr * path) : pos(pos), path(path) { };
COMMON_METHODS
};
/* Static environments are used to map variable names onto (level,
displacement) pairs used to obtain the value of the variable at
+2 -1
View File
@@ -270,7 +270,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%token <nf> FLOAT
%token <path> PATH HPATH SPATH
%token <uri> URI
%token IF THEN ELSE ASSERT WITH LET IN REC INHERIT EQ NEQ AND OR IMPL OR_KW
%token IF THEN ELSE ASSERT WITH LET IN REC INHERIT EQ NEQ AND OR IMPL OR_KW INCLUDE
%token DOLLAR_CURLY /* == ${ */
%token IND_STRING_OPEN IND_STRING_CLOSE
%token ELLIPSIS
@@ -348,6 +348,7 @@ expr_app
: expr_app expr_select
{ $$ = new ExprApp(CUR_POS, $1, $2); }
| expr_select { $$ = $1; }
| INCLUDE expr_select { $$ = new ExprInclude(CUR_POS, $2); }
;
expr_select
+15 -4
View File
@@ -1913,21 +1913,32 @@ static void prim_replaceStrings(EvalState & state, const Pos & pos, Value * * ar
auto s = state.forceString(*args[2], context, pos);
string res;
for (size_t p = 0; p < s.size(); ) {
// Loops one past last character to handle the case where 'from' contains an empty string.
for (size_t p = 0; p <= s.size(); ) {
bool found = false;
auto i = from.begin();
auto j = to.begin();
for (; i != from.end(); ++i, ++j)
if (s.compare(p, i->size(), *i) == 0) {
found = true;
p += i->size();
res += j->first;
if (i->empty()) {
if (p < s.size())
res += s[p];
p++;
} else {
p += i->size();
}
for (auto& path : j->second)
context.insert(path);
j->second.clear();
break;
}
if (!found) res += s[p++];
if (!found) {
if (p < s.size())
res += s[p];
p++;
}
}
mkString(v, res, context);
@@ -2225,7 +2236,7 @@ void EvalState::createBaseEnv()
/* Add a wrapper around the derivation primop that computes the
`drvPath' and `outPath' attributes lazily. */
string path = settings.nixDataDir + "/nix/corepkgs/derivation.nix";
string path = canonPath(settings.nixDataDir + "/nix/corepkgs/derivation.nix", true);
sDerivationNix = symbols.create(path);
evalFile(path, v);
addConstant("derivation", v);
+1 -1
View File
@@ -79,7 +79,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
ref = "HEAD"s;
}
if (!ref) ref = "master"s;
if (!ref) ref = "HEAD"s;
if (rev != "" && !std::regex_match(rev, revRegex))
throw Error("invalid Git revision '%s'", rev);
+2 -2
View File
@@ -717,7 +717,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
Path tmpDir = createTempDir();
AutoDelete autoDelete(tmpDir, true);
// FIXME: this requires GNU tar for decompression.
runProgram("tar", true, {"xf", storePath, "-C", tmpDir, "--strip-components", "1"});
runProgram("tar", true, {"xf", store->toRealPath(storePath), "-C", tmpDir, "--strip-components", "1"});
unpackedStorePath = store->addToStore(name, tmpDir, true, htSHA256, defaultPathFilter, NoRepair);
}
replaceSymlink(unpackedStorePath, unpackedLink);
@@ -727,7 +727,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
if (expectedStorePath != "" && storePath != expectedStorePath)
throw nix::Error("store path mismatch in file downloaded from '%s'", url);
return storePath;
return store->toRealPath(storePath);
}
+7
View File
@@ -73,6 +73,13 @@ std::map<std::string, std::string> getEnv()
}
void clearEnv()
{
for (auto & name : getEnv())
unsetenv(name.first.c_str());
}
Path absPath(Path path, Path dir)
{
if (path[0] != '/') {
+3
View File
@@ -32,6 +32,9 @@ string getEnv(const string & key, const string & def = "");
/* Get the entire environment. */
std::map<std::string, std::string> getEnv();
/* Clear the environment. */
void clearEnv();
/* Return an absolutized path, resolving paths relative to the
specified directory, or the current directory otherwise. The path
is also canonicalised. */
+1 -3
View File
@@ -16,8 +16,6 @@ using namespace nix;
std::string chrootHelperName = "__run_in_chroot";
extern char * * environ;
struct CmdRun : InstallablesCommand
{
std::vector<std::string> command = { "bash" };
@@ -109,7 +107,7 @@ struct CmdRun : InstallablesCommand
if (s) kept[var] = s;
}
environ = nullptr;
clearEnv();
for (auto & var : kept)
setenv(var.first.c_str(), var.second.c_str(), 1);
+1
View File
@@ -0,0 +1 @@
true
+16
View File
@@ -0,0 +1,16 @@
assert include ./include-1.nix == 1;
assert let x = 100; in include ./include-1.nix == 1;
assert with { x = 123; }; include ./include-1.nix == 1;
assert let x = 2; in include ./include-2.nix == 3;
assert let x = 3; in include ./include-2.nix == 4;
assert let x = 3; in let x = 4; in include ./include-2.nix == 5;
assert let x = 3; in let x = 4; in include ./include-2.nix == 5;
assert let x = 6; in with { x = 7; }; include ./include-2.nix == 7;
assert with { x = 0; }; let x = 6; in with { x = 7; }; include ./include-2.nix == 7;
assert with { x = 0; }; let x = 6; in with { x = 7; }; let x = 7; in include ./include-2.nix == 8;
assert with { x = 8; }; include ./include-2.nix == 9;
assert (let x = 10; in include ./include-3.nix) == 3628800;
true
+1 -1
View File
@@ -1 +1 @@
[ "faabar" "fbar" "fubar" "faboor" "fubar" ]
[ "faabar" "fbar" "fubar" "faboor" "fubar" "XaXbXcX" "X" "a_b" ]
+3
View File
@@ -5,4 +5,7 @@ with builtins;
(replaceStrings ["oo"] ["u"] "foobar")
(replaceStrings ["oo" "a"] ["a" "oo"] "foobar")
(replaceStrings ["oo" "oo"] ["u" "i"] "foobar")
(replaceStrings [""] ["X"] "abc")
(replaceStrings [""] ["X"] "")
(replaceStrings ["-"] ["_"] "a-b")
]
+1
View File
@@ -0,0 +1 @@
let x = 1; in x
+1
View File
@@ -0,0 +1 @@
1 + x
+1
View File
@@ -0,0 +1 @@
if x > 0 then x * (let x_ = x; in let x = x_ - 1; in include ./include-3.nix) else 1