NixOS / NixOS/nix

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

Open
#11,633 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
C++
Stars
17.7k
Forks
2k
Avg merge
1d 19h
Merged PRs (30d)
76

Description

Problem

The manual entry states:
https://github.com/NixOS/nix/blob/4e8a9e0ed4ce9edcaec4e7939e3bfff2f060edb8/doc/manual/src/language/import-from-derivation.md?plain=1#L7

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open doc/manual/src/language/import-from-derivation.md and read the linked paragraph describing when IFD occurs. Revise the wording to distinguish derivation output paths from other store paths, then check the rendered manual to confirm the explanation and existing function list remain clear.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.