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

treewide: get rid of with lib; and friends #209325

Closed
wants to merge 7 commits into from
Closed

treewide: get rid of with lib; and friends #209325

wants to merge 7 commits into from

Conversation

AndersonTorres
Copy link
Member

@AndersonTorres AndersonTorres commented Jan 6, 2023

Description of changes

Tracks

#208242

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • 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/)
  • 23.05 Release Notes (or backporting 22.11 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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@AndersonTorres AndersonTorres marked this pull request as draft January 6, 2023 15:34
@github-actions github-actions bot added 6.topic: cinnamon Desktop environment 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: pantheon The Pantheon desktop environment 8.has: module (update) This PR changes an existing module in `nixos/` labels Jan 6, 2023
@AndersonTorres
Copy link
Member Author

I am cogitating if it is better to split this per file.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 6, 2023
@@ -2,8 +2,6 @@

{ config, lib, pkgs, ... }:

with lib;
Copy link
Contributor

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.

Copy link
Member Author

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".

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea.

Copy link
Member

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

Comment on lines 4 to 5
inherit (lib)
literalExpression mdDoc mkIf mkMerge mkOption mkRenamedOptionModule types;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@AndersonTorres AndersonTorres Jan 13, 2023

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?

Copy link
Member

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.

Copy link
Member Author

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 = [ ];?

@github-actions github-actions bot added 6.topic: emacs Text editor 6.topic: cinnamon Desktop environment 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: golang 6.topic: ocaml 6.topic: pantheon The Pantheon desktop environment 6.topic: python 6.topic: stdenv Standard environment 8.has: module (update) This PR changes an existing module in `nixos/` and removed 6.topic: emacs Text editor 6.topic: cinnamon Desktop environment 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: pantheon The Pantheon desktop environment 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: stdenv Standard environment 6.topic: python 6.topic: golang labels Jan 11, 2023
Copy link
Member

@SuperSandro2000 SuperSandro2000 left a 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;
Copy link
Member

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

services.udev.packages = with pkgs; [
gkraken
];
services.udev.packages = [ pkgs.gkraken ];
Copy link
Member

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.

Comment on lines 6 to 7
inherit (lib)
mdDoc mkEnableOption mkIf;
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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.

Comment on lines 112 to 114
description = mdDoc ''
A script that runs the service outside of systemd, useful for testing or
for using NixOS services outside of NixOS.
'';
Copy link
Member

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.

Comment on lines 8 to 10
{ pkgs, lib, ... }: let
inherit (lib) listToAttrs nameValuePair;
in
Copy link
Member

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.

Comment on lines 8 to 10
meta.maintainers = builtins.attrValues {
inherit (lib.maintainers) freezeboy k900;
};
Copy link
Member

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.

Copy link
Member Author

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.

meta = with lib; {
maintainers = teams.gnome.members;
};
meta.maintainers = lib.teams.gnome.members;
Copy link
Member

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 👍🏼

meta = with pkgs.lib.maintainers; {
maintainers = [ globin yayayayaka ];
};
meta.maintainers = with lib.maintainers; [ globin yayayayaka ];
Copy link
Member

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

Comment on lines 3 to 5
with lib;

{
name = "fluidd";
meta.maintainers = with maintainers; [ vtuan10 ];
meta.maintainers = with lib.maintainers; [ vtuan10 ];
Copy link
Member

Choose a reason for hiding this comment

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

Great change 👍🏼

@github-actions github-actions bot removed 6.topic: emacs Text editor 6.topic: pantheon The Pantheon desktop environment 6.topic: cinnamon Desktop environment 6.topic: GNOME GNOME desktop environment and its underlying platform labels Jan 14, 2023
@AndersonTorres
Copy link
Member Author

Small steps.

@AndersonTorres AndersonTorres marked this pull request as ready for review January 14, 2023 03:26
@SuperSandro2000 SuperSandro2000 marked this pull request as draft January 23, 2023 22:17
@AndersonTorres
Copy link
Member Author

Closing because headache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants