I often do something like this.
foo = pkgs.writeShellApplication {
name = "foo";
text = builtins.readFile ./foo.sh;
};
Then I recently learnt about Import From Derivation (IFD), and the fact that it might cause a performance penalty during nix evaluation.
The docs says Passing an expression expr that evaluates to a store path to any built-in function which reads from the filesystem constitutes Import From Derivation (IFD)
, and builtins.readFile
was also listed there as one of those functions.
Then I learned that I can pass --option allow-import-from-derivation false
to nix build
command to make it fail when IFD is detected. But the expression I wrote above were built successfully.
So I want to clarify my understandings and assumptions about what happened.
- When I run
nix build
, the whole repository was copied to nix store before start evaluating. - We didn’t hit the performance penalty, because during evaluation,
./foo.sh
is already in nix store, hence nothing to build, and nothing blocks evaluation. - Nix build was smart enough to classify above expression as not blocking evaluation, by looking at the argument passed to
builtins.readFile
, which was apath
data type, not a string. - We are safe from IFD performance penalty as long as we use
--option allow-import-from-derivation false
, even if we use builtin functions that causes IFD mentioned in docs. In other word, no manual check is necessary to avoid IFD performance penalty as long as we pass the flag.
Please let me know if I understand any of above wrong.
Thank you