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

lib: Discourage use of extend #376033

Merged
merged 2 commits into from
Feb 9, 2025

Conversation

roberth
Copy link
Member

@roberth roberth commented Jan 23, 2025

It creates interoperability issues that can not be reconciled by lib or maintainers of projects that use the Nixpkgs library. Occasionally, end users may be able to solve the problems they run into, but most are not prepared to deal with this set of problems, nor should they be.

Typical conflict:

  • User wants to propagate their own lib, because it has some function they like to use throughout their projects
  • Project maintainer requires the project's lib to be used

No sane language uses a single namespace for combining all the things. (Arguably not even C with its extensive use of prefixing)

Meanwhile, in Nix, all symbols are first class variables. We don't even have the concept of a global top-level namespace to pour everything into. With lib you can try to approximate that, I get the appeal of its apparent simplicity, but since lib can't be global, we just don't even get that apparent simplicity.

I apologize for not offering concrete solutions to this in the text. The manuals are limited to reference documentation. Alternatives - of which we have multiple - are best provided in task-oriented documentation, e.g. nix.dev.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

It creates interoperability issues that can not be reconciled by
`lib` or maintainers of projects that use the Nixpkgs library.
Occasionally, end users may be able to solve the problems they run
into, but most are not prepared to deal with this set of problems,
nor should they be.

Typical conflict:
- User wants to propagate their own lib, because it has some function
  they like to use throughout their projects
- Project maintainer requires the project's lib to be used

No sane language uses a single namespace for combining all the things.
(Arguably not even C with its extensive use of prefixing)

Meanwhile, in Nix, all symbols are first class variables. We don't even
have the concept of a global top-level namespace to pour everything into.
With `lib` you can try to approximate that, I get the appeal of its
apparent simplicity, but since `lib` can't be global, we just don't even
get that apparent simplicity.

I apologize for not offering concrete solutions to this in the text.
The manuals are limited to reference documentation.
Alternatives - of which we have multiple - are best provided in
task-oriented documentation, e.g. nix.dev.
@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 6.topic: flakes The experimental Nix feature 6.topic: lib The Nixpkgs function library labels Jan 23, 2025
@roberth roberth requested a review from philiptaron January 23, 2025 07:40
@nix-owners nix-owners bot requested a review from infinisil January 23, 2025 07:42
Copy link
Contributor

@hsjobeki hsjobeki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.
I dont know how to display the doc-comment in the repl or on noogle for this yet.

lib/default.nix Show resolved Hide resolved
@roberth
Copy link
Member Author

roberth commented Jan 29, 2025

how to display the doc-comment in the repl

Seems to work in the repl, Nix 2.25

nix-repl> :doc lib.extend
Function extend
    … defined at /home/user/h/nixpkgs/lib/default.nix:38:20

    Patch the Nixpkgs library
[...]

I guess for nixdoc we'd have to construct a fake sublibrary to represent the top level or something to make it work? We can't just do lib because that has a copy of a majority of functions.

Co-authored-by: Johannes Kirschbauer <[email protected]>
@roberth roberth merged commit a7c2010 into NixOS:master Feb 9, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: flakes The experimental Nix feature 6.topic: lib The Nixpkgs function library 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants