-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
treewide: get rid of with lib;
and friends
#209325
Conversation
I am cogitating if it is better to split this per file. |
@@ -2,8 +2,6 @@ | |||
|
|||
{ config, lib, pkgs, ... }: | |||
|
|||
with lib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a PR with only those removals, since this one can be merged really fast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not following.
My idea is that each commit should be buildable. If I merely remove the with lib
and merge, obviously it will generate errors like "mkDefault not defined".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? That this commit is broken them? Because it is clear that a few files only remove with lib;
and do nothing else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am talking about only about the files that remove with lib;
and do nothing else BTW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, same idea from me. If we can remove a with
anywhere without having regressions we can immediately merge it. This can also be done treewide to make mistakes in commits unlikely.
This change is uncontroversial for me
inherit (lib) | ||
literalExpression mdDoc mkIf mkMerge mkOption mkRenamedOptionModule types; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is not an improvement over just prefixing things with lib.
or using with lib
more locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this first moment I am more interested in make the expressions compile. More cosmetic modifications can be done later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am talking about the general idea of your change. If the next person (for example me) is going to revert this again because maintaining a list of used functions is not worth it, then we didn't achieve anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "idea" of my change is just getting rid of with
.
For this draft phase, I believe it is easier to use inherit (lib) every thing that was called;
. It will help a future automation.
I have no problem in prefixing lib.
This can be done with the help of an Emacs quick&dirty magic keystroke. Indeed I will do this tonight.
I am more reticent about "using lib more locally". It is becoming ridiculous to see "mkDefault" in a line and "lib.mdDoc" in the next one.
And it is depressing to look at meta = with pkgs.lib.maintainers; { maintainers = []; };
. Such a heavy machinery to empty lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it is depressing to look at
meta = with pkgs.lib.maintainers; { maintainers = []; };
. Such a heavy machinery to empty lists?
It is empty to convey that the package needs a maintainer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is empty to convey that the package needs a maintainer.
What is the difference for meta.maintainers = [ ];
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't merge this before we don't have some consensus otherwise the next person is going to revert it and then we all are not making good use of our time.
I would suggest that we split out all the uncontroversial changes into separate, treewide PRs so that they can be merged faster and the merge conflicts are reduced.
Also please do not self merge this PR.
@@ -2,8 +2,6 @@ | |||
|
|||
{ config, lib, pkgs, ... }: | |||
|
|||
with lib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, same idea from me. If we can remove a with
anywhere without having regressions we can immediately merge it. This can also be done treewide to make mistakes in commits unlikely.
This change is uncontroversial for me
nixos/modules/hardware/gkraken.nix
Outdated
services.udev.packages = with pkgs; [ | ||
gkraken | ||
]; | ||
services.udev.packages = [ pkgs.gkraken ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me the line before the change was so easy to understand that I can parse it at first glimpse without thinking. I can no longer do that with pkgs.
especially if there are multiple.
nixos/modules/hardware/gkraken.nix
Outdated
inherit (lib) | ||
mdDoc mkEnableOption mkIf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each of those functions is used once. The file is not even 20 lines long. Both the inherit and with should be dropped and the three occurrences of lib should just be written out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being redundant, my primary concern here is to make the code compile without with
.
After this, it will be easy to prefix lib.
OTOH I don't believe this is bad code. It is similar to other programming languages like C++ namespaces and Python lib imports.
@@ -121,7 +122,7 @@ in | |||
{ | |||
options = { | |||
systemd.services = mkOption { | |||
type = with types; attrsOf (submodule opts); | |||
type = attrsOf (submodule opts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This usage of lib is totally fine for me and I see a lot of people doing it when writing modules. IMO we should keep it.
description = mdDoc '' | ||
A script that runs the service outside of systemd, useful for testing or | ||
for using NixOS services outside of NixOS. | ||
''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not change formatting that changes the code to avoid unnecessary possibilities regressions.
nixos/tests/redis.nix
Outdated
{ pkgs, lib, ... }: let | ||
inherit (lib) listToAttrs nameValuePair; | ||
in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to either prefix the functions with lib.
or move the with lib to the function.
nixos/tests/n8n.nix
Outdated
meta.maintainers = builtins.attrValues { | ||
inherit (lib.maintainers) freezeboy k900; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this code is now actually worse and not understandable for a beginner. I am against changing multi maintainer entries to use a function instead of being a list which uses with very locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beginners mostly copy and paste examples. Many of them still tops with lib;
without knowing why - ans this is demonstrated by the use of lib.mdDoc
.
nixos/tests/gnome-xorg.nix
Outdated
meta = with lib; { | ||
maintainers = teams.gnome.members; | ||
}; | ||
meta.maintainers = lib.teams.gnome.members; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good change 👍🏼
nixos/tests/gitlab.nix
Outdated
meta = with pkgs.lib.maintainers; { | ||
maintainers = [ globin yayayayaka ]; | ||
}; | ||
meta.maintainers = with lib.maintainers; [ globin yayayayaka ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have done the same
nixos/tests/fluidd.nix
Outdated
with lib; | ||
|
||
{ | ||
name = "fluidd"; | ||
meta.maintainers = with maintainers; [ vtuan10 ]; | ||
meta.maintainers = with lib.maintainers; [ vtuan10 ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change 👍🏼
Small steps. |
Closing because headache. |
Description of changes
Tracks
#208242
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes