Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
infinisil opened this issue Nov 7, 2023 · 0 comments
Open
Labels
6.topic: lib The Nixpkgs function library

Comments

@infinisil
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library
Projects
None yet
Development

No branches or pull requests

1 participant