Skip to content

Resolve //path to flake root #12070

Closed
Closed
@msanft

Description

@msanft

Is your feature request related to a problem?

Users of flakes in repositories with somewhat-nested tree layouts often get into positions where they have to:

import ../../../../foo.nix

This is error-prone. For example, if foo.nix gets moved around, it's easy to add a ../ too much, causing errors.
Furthermore, this is very much not nice to look at.

Proposed solution

Resolve a path of form //path to the flake's root directory. If I have a flake.nix in /home/me/my-project/flake.nix, and the project layout is as follows:

  • /home/me/my-project/foo/bar.nix:
    • "foo"
  • /home/me/my-project/some/deeply/nested/tree/package.nix:
    • import //foo/bar.nix

Evaluating /home/me/my-project/some/deeply/nested/tree/package.nix should return "foo".

Alternative solutions

Passing self around should work, but having a short-hand path operation for this would be nice.

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingChanges we can't make without breaking old expressions, changing hashes, etcfeatureFeature request or proposalflakes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions