Skip to content

reword documentation on nix-path config option#7772

Merged
fricklerhandwerk merged 2 commits intoNixOS:masterfrom
fricklerhandwerk:restrict-eval
Jul 31, 2024
Merged

reword documentation on nix-path config option#7772
fricklerhandwerk merged 2 commits intoNixOS:masterfrom
fricklerhandwerk:restrict-eval

Conversation

@fricklerhandwerk
Copy link
Copy Markdown
Contributor

@fricklerhandwerk fricklerhandwerk commented Feb 7, 2023

also make the fallback values explicit.

Motivation

this is to clarify behavior. using the positive boolean is easier to read,
as it does not require flipping bits in your head.

Context

Follow-up on #7689 by @ncfavier instead of making a post-factum review.

Update: unfortunately that PR did not actually implement the desired behavior.

Depends on: #7871

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or bug fix: updated release notes

Comment thread src/libexpr/eval.hh Outdated
Comment thread src/libexpr/eval.hh Outdated
Comment thread src/libexpr/eval.hh Outdated
@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-44/25546/1

@Ericson2314
Copy link
Copy Markdown
Member

Or we trying to document the current behavior or the intended behavior? Because this to me is not quitethe intended behavior.

The rules I wrote in #7871 (comment) are not intended to be just just for nixPath but for any such configuration variable. The rules around settings files, NIX_CONF, --extra-foo, and --foo are entirely standard and additionally rules for NIX_FOO go for many other such configuration options that also have their own env vars.

Documenting this stuff per a specific option like nixPath implies that it is somehow special. It is today because of the weirdness of "restricted eval" that is in conflict with these general rules. But we should fix "restricted eval"` so as to not break those rules instead. Then we can restore the general pattern and not have special cases.

@fricklerhandwerk
Copy link
Copy Markdown
Contributor Author

I agree this should just follow the standard pattern. But since there are four possibilities of changing the search path, I opted for making that explicit here. We don't have to do it that way, and I'm open for concrete suggestions.

@Ericson2314
Copy link
Copy Markdown
Member

Ericson2314 commented Mar 6, 2023

@fricklerhandwerk I am thinking of adding to BaseSettings an optEnvVar. And then we can programmatically document this for all of them! :)

(Or maybe it would be sub-class.)

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-45/26397/1

@fricklerhandwerk
Copy link
Copy Markdown
Contributor Author

Triaged in the Nix team meeting 2023-03-31:

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-31-nix-team-meeting-minutes-45/27002/1

@dpulls
Copy link
Copy Markdown

dpulls Bot commented Jul 24, 2024

🎉 All dependencies have been resolved !

@github-actions github-actions Bot added documentation with-tests Issues related to testing. PRs with tests have some priority labels Jul 25, 2024
@fricklerhandwerk fricklerhandwerk marked this pull request as ready for review July 25, 2024 01:41
- put all the information on search path semantics into `builtins.findFile`
- put all the information on determining the value of `builtins.nixPath` into the
  `nix-path` setting

  maybe `builtins.nixPath` is a better place for this, but those bits
  can still be moved around now that it's all next to each other.
- link to the syntax page for lookup paths from all places that are
  concerned with it
- add or clarify examples
- add a test verifying a claim from documentation
@fricklerhandwerk fricklerhandwerk merged commit db5bacb into NixOS:master Jul 31, 2024
Comment on lines -94 to -162
Add *path* to the Nix search path. The Nix search path is
initialized from the colon-separated [`NIX_PATH`](@docroot@/command-ref/env-common.md#env-NIX_PATH) environment
variable, and is used to look up the location of Nix expressions using [paths](@docroot@/language/types.md#type-path) enclosed in angle
brackets (i.e., `<nixpkgs>`).
Add *path* to search path entries used to resolve [lookup paths](@docroot@/language/constructs/lookup-path.md)

For instance, passing
This option may be given multiple times.

```
-I /home/eelco/Dev
-I /etc/nixos
```

will cause Nix to look for paths relative to `/home/eelco/Dev` and
`/etc/nixos`, in that order. This is equivalent to setting the
`NIX_PATH` environment variable to

```
/home/eelco/Dev:/etc/nixos
```

It is also possible to match paths against a prefix. For example,
passing

```
-I nixpkgs=/home/eelco/Dev/nixpkgs-branch
-I /etc/nixos
```

will cause Nix to search for `<nixpkgs/path>` in
`/home/eelco/Dev/nixpkgs-branch/path` and `/etc/nixos/nixpkgs/path`.

If a path in the Nix search path starts with `http://` or `https://`,
it is interpreted as the URL of a tarball that will be downloaded and
unpacked to a temporary location. The tarball must consist of a single
top-level directory. For example, passing

```
-I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz
```

tells Nix to download and use the current contents of the `master`
branch in the `nixpkgs` repository.

The URLs of the tarballs from the official `nixos.org` channels
(see [the manual page for `nix-channel`](../nix-channel.md)) can be
abbreviated as `channel:<channel-name>`. For instance, the
following two flags are equivalent:

```
-I nixpkgs=channel:nixos-21.05
-I nixpkgs=https://nixos.org/channels/nixos-21.05/nixexprs.tar.xz
```

You can also fetch source trees using [flake URLs](./nix3-flake.md#url-like-syntax) and add them to the
search path. For instance,

```
-I nixpkgs=flake:nixpkgs
```

specifies that the prefix `nixpkgs` shall refer to the source tree
downloaded from the `nixpkgs` entry in the flake registry. Similarly,

```
-I nixpkgs=flake:github:NixOS/nixpkgs/nixos-22.05
```

makes `<nixpkgs>` refer to a particular branch of the
`NixOS/nixpkgs` repository on GitHub.
Copy link
Copy Markdown

@n0099 n0099 Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO moving this part to src/libexpr/primops.cc make it harder to understand that -I a=b means search path attrs set { prefix: a, path: b } in https://nix.dev/manual/nix/2.24/language/builtins.html#builtins-findFile.

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/selecting-a-channel-with-nix-shell/4247/9

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

Labels

documentation with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants