forked from lix-project/lix
* Primop builtins.storePath for declaring a store path as a
dependency. `storePath /nix/store/bla' gives exactly the same result as `toPath /nix/store/bla', except that the former includes /nix/store/bla in the dependency context of the string. Useful in some generated Nix expressions like nix-push, which now finally does the right thing wrt distributed builds. (Previously the path to be packed wasn't an explicit dependency, so it wouldn't be copied to the remote machine.)
This commit is contained in:
parent
60564410ef
commit
aab530e971
|
@ -107,7 +107,7 @@ foreach my $storePath (@storePaths) {
|
||||||
# Construct a Nix expression that creates a Nix archive.
|
# Construct a Nix expression that creates a Nix archive.
|
||||||
my $nixexpr =
|
my $nixexpr =
|
||||||
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
||||||
"{storePath = builtins.toPath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) ";
|
"{storePath = builtins.storePath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) ";
|
||||||
|
|
||||||
print NIX $nixexpr;
|
print NIX $nixexpr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,6 +482,27 @@ static Expr prim_toPath(EvalState & state, const ATermVector & args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Allow a valid store path to be used in an expression. This is
|
||||||
|
useful in some generated expressions such as in nix-push, which
|
||||||
|
generates a call to a function with an already existing store path
|
||||||
|
as argument. You don't want to use `toPath' here because it copies
|
||||||
|
the path to the Nix store, which yields a copy like
|
||||||
|
/nix/store/newhash-oldhash-oldname. In the past, `toPath' had
|
||||||
|
special case behaviour for store paths, but that created weird
|
||||||
|
corner cases. */
|
||||||
|
static Expr prim_storePath(EvalState & state, const ATermVector & args)
|
||||||
|
{
|
||||||
|
PathSet context;
|
||||||
|
Path path = canonPath(coerceToPath(state, args[0], context));
|
||||||
|
if (!isInStore(path))
|
||||||
|
throw EvalError(format("path `%1%' is not in the Nix store") % path);
|
||||||
|
if (!store->isValidPath(path))
|
||||||
|
throw EvalError(format("store path `%1%' is not valid") % path);
|
||||||
|
context.insert(toStorePath(path));
|
||||||
|
return makeStr(path, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_pathExists(EvalState & state, const ATermVector & args)
|
static Expr prim_pathExists(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
|
@ -950,6 +971,7 @@ void EvalState::addPrimOps()
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
addPrimOp("__toPath", 1, prim_toPath);
|
addPrimOp("__toPath", 1, prim_toPath);
|
||||||
|
addPrimOp("__storePath", 1, prim_storePath);
|
||||||
addPrimOp("__pathExists", 1, prim_pathExists);
|
addPrimOp("__pathExists", 1, prim_pathExists);
|
||||||
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
||||||
addPrimOp("dirOf", 1, prim_dirOf);
|
addPrimOp("dirOf", 1, prim_dirOf);
|
||||||
|
|
Loading…
Reference in a new issue