Does importing a store path consitute import from derivation (IFD)

Hello,

I don’t understand the definition of Import From Derivation from CppNix’s Documentation. It (version 2.33.4) 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…

Here are some examples that confuses me (suppose that nixpkgs is in the store):

  • Angle bracket syntax path
    Say that we have a <nixpkgs> in the NIX_PATH and I wish to access lib in it. I do import <nixpkgs/lib>.

  • Path concatenation
    Say that I have a source managed with niv or npins and I want to access lib in it. I do import (sources.nixpkgs + "/lib").

  • Relative path in flake context
    When evaluating a flake, the entire directory is copied to the store. I do import ./someFileInFlake.nix.

  • An attribute of a derivation
    Say that nixpkgs is fetched with fetchFromGitHub, which returns a derivation. I do import (import nixpkgs {}).path {} (consider the outer import. I suppose the inner one is IFD?)

In all scenarios I read into a nix expression in the store using import, so the expression I’m importing from technically depends on a derivation. But at the same time, they are path types, not derivations. They themselves (e.g. <nixpkgs/lib>) cannot be realised. Doing :b <nixpkgs/lib> in the repl will give you a

error:
expression does not evaluate to a derivation, so I can’t build it

Are they IFDs ?

Thank you for reading my question!

Importing from [reading the contents of] a nix expression that uses builtins.derivation [into the nix evaluator] is IFD.

Things like "${./file}" and flake inputs are not derivations.

1 Like

Does that means importing from the same nixpkgs checkout with different fetchers can change whether IFD is used or not?

For example, pkgs.fetchFromGitHub uses stdenvNoCC.mkDerivation and hence builtins.derivation; builtins.fetchTarball is a builtin itself and doesn’t build a derivation. Importing from the nixpkgs fetched with builtins.fetchFromGitHub and builtins.fetchTarball will use and not use IFD respectively?

Correct.​​​​​​​​​​​​​​ fetchFromGitHub uses nix code (+bash), builtins are all c++ code, hence their fetching mechanisms are quite different.

1 Like