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

Document import <path> syntax #3159

Merged
merged 4 commits into from Oct 23, 2019
Merged

Conversation

ersinakinci
Copy link
Contributor

Fixes #338 by changing the start of the manual section on builtins.import to the following:

import path, import <path>, builtins.import path, builtins.import <path>

Load, parse and return the Nix expression in the file path. If path is a directory, the file default.nix in that directory is loaded. If the <path> syntax is used, the path will be resolved relative to those listed in the NIX_PATH environment variable (see the section on NIX_PATH for details on how the resolution works). Evaluation aborts if the file doesn’t exist or contains an incorrect Nix expression. import implements Nix’s module system: you can put any Nix expression (such as a set or a function) in a separate file, and use it from Nix expressions in other files.

@edolstra
Copy link
Member

There is no import <path> syntax. import is a function that takes a value and <path> is a value. So import <path> is equivalent to e.g. let p = <path>; in import p. The <path> syntax is already documented:

  <para>Paths can also be specified between angle brackets, e.g.
  <literal>&lt;nixpkgs&gt;</literal>. This means that the directories
  listed in the environment variable
  <envar linkend="env-NIX_PATH">NIX_PATH</envar> will be searched
  for the given file or directory name.
  </para>

@ersinakinci
Copy link
Contributor Author

ersinakinci commented Oct 21, 2019

@edolstra, that makes perfect sense. I didn't realize that paths can be written with angle brackets, which of course is implied by the fact that import is a function, not a special keyword.

I do think that for beginners coming from other languages where import often has special syntax, this can be a point of confusion, even though <path> is documented. I've updated my PR accordingly to provide a "hint" in the section on builtins.import.

What do you think?

@edolstra edolstra merged commit dfe1fdf into NixOS:master Oct 23, 2019
@edolstra
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

Document import <...> syntax in "Writing Nix Expressions" chapter of manual
3 participants