User cleveron IRC #nixosexplained:
When will this happen
An extension to /nix/store/...occurs when you use a path inside ${}string interpolation , for example mystring = "cat ${./myfile.txt}.
This does not happen if you use a functiontoString , for example. toString ./myfile.txtwill not give you a path pointing to /nix/store.
For instance:
toString ./notes.txt == "/home/clever/apps/nixos-installer/installer-gui/notes.txt"
"${./notes.txt}" == "/nix/store/55j24v9qwdarikv7kd3lc0pvxdr9r2y8-notes.txt"
How does this happen
The hash part 55j24v9qwdarikv7kd3lc0pvxdr9r2y8is taken from the contents of the referenced file, ./pathso that it changes when the file changes, and everything that depends on it can be rebuilt accordingly.
/nix/store nix-instantiate; nix- - ( ), ( "building" ) .
, nix "", , ( .drv).
, "/nix/store/rkvwvi007k7w8lp4cc0n10yhlz5xjfmk-hello-2.10" GNU hello , , hello. stdenv.mkDerivation, " " hello.
, builtins.substring. . nix , 1653 1657.
, builtins.unsafeDiscardStringContext.
nix
${} coerceToString, bool copyToStore, true:
string coerceToString(const Pos & pos, Value & v, PathSet & context,
bool coerceMore = false, bool copyToStore = true);
, ./path /nix/store :
if (v.type == tPath) {
Path path(canonPath(v.path));
return copyToStore ? copyPathToStore(context, path) : path;
}
toString prim_toString false copyToStore:
static void prim_toString(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
PathSet context;
string s = state.coerceToString(pos, *args[0], context, true, false);
mkString(v, s, context);
}