Skip to content

Don't expose all functions in the top-level lib, prefer sub-libraries #266103

@infinisil

Description

@infinisil

lib is a bit messy right now, where some functions are available in lib.*, but some need to be accessed as lib.<sublibrary>.*.

Traditionally all functions were available under lib.*, but in recent years we've seen that it doesn't work that well. An example is how lib.hasPrefix works on strings, it's aliased to lib.strings.hasPrefix. But it also makes sense to have such functionality for lists and paths, we should be able to re-use the same name. This is now done:

But lib.hasPrefix still needs to point to lib.strings.hasPrefix for backwards compat, and this previously caused problems when accidentally using lib.hasPrefix for paths:

Furthermore, lib is tending towards the style more emphasised since

{ lib }:
let
  inherit (lib.lists)
    length;

  inherit (lib.strings)
    hasPrefix;
in
...

which makes sublibraries not much harder to use (no need to always use lists.length).

We should establish a standard for sublibraries and make sure it's consistent.

Related issues/comments:

Ping @roberth @h7x4

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: libThe Nixpkgs function library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions