Skip to content

Manual entry on IFD does not consider store paths not produced by derivations #11633

Open
@max-privatevoid

Description

Problem

The manual entry states:

Passing an expression `expr` that evaluates to a [store path](@docroot@/store/store-path.md) to any built-in function which reads from the filesystem constitutes Import From Derivation (IFD):

However, "an expression expr that evaluates to a store path" does not necessarily involve a derivation. It may also be produced by a built-in fetcher.

Nix also agrees that builtins.fetchurl is not IFD:

let
  pkgs = import <nixpkgs> {};

  name = "funny.txt";
  url = "https://example.com";
  sha256 = "sha256-6o+sfGX7WJsNU1YPUlH3T56bJDR43Laz6nm142RJyNk=";
in
{
  viaBuiltins = builtins.readFile (builtins.fetchurl {
    inherit name url sha256;
  });
  viaPkgs = builtins.readFile (pkgs.fetchurl {
    inherit name url sha256;
  });
}
$ nix eval -f example.nix --no-allow-import-from-derivation viaPkgs
error:
       … while calling the 'readFile' builtin
         at /tmp/tmp.sjf6pjcR2J/example.nix:12:13:
           11|   });
           12|   viaPkgs = builtins.readFile (pkgs.fetchurl {
             |             ^
           13|     inherit name url sha256;

       … while realising the context of path '/nix/store/ppsywqzjm5v8nvki3swzx4zrri55ppcp-funny.txt'

       error: cannot build '/nix/store/5x8v83jldidwrn9vg8w9wr9y2r3x04p4-funny.txt.drv^out' during evaluation because the option 'allow-import-from-derivation' is disabled

$ nix eval -f example.nix --no-allow-import-from-derivation viaBuiltins
"[html content of example.com]"

Proposal

The paragraph should somehow mention that it's only IFD when the store path is produced by a derivation. The existing sentence is already pretty long and complex, so maybe using a list would make it easier to understand:

Import From Derivation (IFD) occurs when:

  • an expression expr, which evaluates to a store path
  • is passed to any built-in function which reads from the filesystem
  • and the store path in question is an output path of a derivation

The following are built-in functions reading from the filesystem:

(the existing list of functions)

Checklist

Priorities

Add 👍 to issues you find important.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions