Skip to content

Overload / to mean path append; alternative to path + "/" + "foo" footgun #7301

@roberth

Description

@roberth

Is your feature request related to a problem? Please describe.

In the Nix language, + associates in such a way that path + "/" + "foo" evaluates to path + "foo" for any path value path.

#6530 pushes people towards this syntax, so perhaps it's worth considering to give them a concise alternative that doesn't lead to almost inexplicable malformed paths every now and then.

Describe the solution you'd like

Instead of

nix-repl> "a" / "b"
error: value is a string while a float was expected

nix-repl> ./. / "b" 
error: value is a string while a float was expected

evaluate to

nix-repl> "a" / "b"
"a/b"

nix-repl> ./. / "b" 
/home/user/src/nixpkgs/b    # assuming such a ./.

Describe alternatives you've considered

Add builtin fetchers to the string context, and add fixed-size holes to strings, so that "${fetchTree foo}/bar" does not immediately fetch the tree.
Holes are a lot to ask though.
Perhaps better phrased as a "rope" of strings and lazy tree thunks. A rope, or lazily concatenated string representation might not be a bad idea?

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    UXThe way in which users interact with Nix. Higher level than UI.featureFeature request or proposalidea 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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions