Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
max-privatevoid opened this issue Oct 3, 2024 · 0 comments
Open
2 tasks done

Comments

@max-privatevoid
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant