Skip to content

New builtin: pathType #3096

@roberth

Description

@roberth

I'm proposing to add a new builtins.pathType that returns the node type, similar to the values returned by builtins.readDir.

Motivation

Avoid having to read a directory when all you need is a single path's node type.

Spec

Like builtins.pathExists, its argument is a path or string that may or may not exist on the filesystem.

Given argument p return value is

  • null when the path p does not point to an existing filesystem node
  • a value equal to (builtins.readDir (dirOf p))."$(baseNameOf p)", such as "directory", "regular", "symlink"

Advantages

  • Performance: no need to read the entire directory (may be big, like /nix/store)
  • Less strict: readDir (dirOf p) may not be allowed by dir permissions
  • Decreases the file watch scope for tools like lorri

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposallanguageThe Nix expression language; parser, interpreter, primops, evaluation, etcstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions