Skip to content

Support the usage of angle brackets for input lookup in flakes #14538

@Frontear

Description

@Frontear

Is your feature request related to a problem?

A longtime issue in the Nix world was the impurity of NIX_PATH. This special magic variable controlled the lookup behaviour of expresisons like import <nixpkgs> {}, making it rather inconsistent and non-reproducible. With flakes, and subsequently pure evaluation, this operator was banned due to the aforementioned issues, and in-place, stricter resolution of such paths was needed. For flakes, one could reference inputs to obtain their relevant paths, and for non-flakes, using the builtin fetchers to procure a store closure (or using external management tools like niv) became the standard.

Overall, this has been a great change, but in this change, we lost a very cool part of the Nix syntax. Legacy code, which heavily relied on this syntax, needs manual migration efforts to replace all references to <some-key> with inputs.some-key. Furthermore, passing around a reference to inputs all over the project can be a non-trivial problem, and can easily become repetitive, error-prone, and rather cumbersome. This is relevant even for non-flake pure evaluation projects, which need some "source of truth", usually in the form of a Nix expression that uses fetchers, located at some central path in a project.

My proposal involves allowing the angle bracket operators to be used in flakes, but with the following restrictions:

  1. Lookup paths are limited to the current flakes inputs. In this sense, NIX_PATH has no influence on the lookups.
  2. When evaluating a flake output, any/all Nix expressions that are evaluated as a part of this evaluation will benefit from this change. If the evaluation of a Nix expression is not part of evaluating a flake output, Nix will fallback to its current behaviour.

Proposed solution

In a flake, when Nix evaluates any angle brackets, rather than querying NIX_PATH, it should query the flake inputs. That is, any Nix expressions of the following form:

import <nixpkgs> {}

should automatically be translated into:

import (some-reference-to-current-flake-inputs).nixpkgs {}

In this manner, one can avoid the concern of needing to delicately pass inputs around a project, migrate legacy code without changing the pre-existing angle brackets, and continue to make the angle bracket syntax useful.

Alternative solutions

Alternatives include (but are not limited to):

  • Passing inputs around the flake project via function parameters. This is a delicate and annoyingly repetitive task.
  • Abusing some level of __nixPath to "fake" <...> lookup in Nix expressions. This is rather hacky and abuses internal languages details.

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions