Skip to content

No short path literals #13374

@roberth

Description

@roberth

TLDR

In expressions, foo/bar bad, ./foo/bar good

Is your feature request related to a problem?

Most path literal expressions start with ./ in practice. (if not ../)
This is a good practice because it makes it clear from the start what's the role of the text that follows.

In fact the use of path literal expressions like foo/bar.nix is sufficiently rare that experienced Nixers are unaware of this possibility (NixOS/nixpkgs#413892)

Perhaps the time has come to take this convention.

Proposed solution

  1. Add a setting to warn or fail when a relative path is encountered that does not start with a .
  2. After some time, default the setting to warn by default

I'd stop there, so that we can keep evaluating old expressions without significant intervention.
Opting out of an error may be hard when multiple hosts are involved in a deployment process that involves evaluation.

Alternative solutions

Linting. This is far less effective. We want everyone to stop using this syntax, not just those who have the knowledge and headspace for it, and we want good coverage; not just the projects that have integrated tooling.

Additional context

  • Similar to no-absolute-path-literals experimental feature #8738

  • A language redesign could parse ./foo/bar as syntax sugar for ${.}/foo/bar or (.)/foo or something. We can't do that because we want to stay compatible, and that involves parsing things like foo/bar directly as a path literal anyway.

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposalgood first issueQuick win for first-time contributorsidea approvedThe given proposal has been discussed and approved by the Nix team. An implementation is welcome.languageThe Nix expression language; parser, interpreter, primops, evaluation, etc
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions