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

docs: clarify package and module option naming #31668

Merged
merged 1 commit into from Dec 23, 2017

Conversation

rycee
Copy link
Member

@rycee rycee commented Nov 14, 2017

So, lately I've been entertaining myself by thinking about package attribute and module names. There is, from what I can tell, a general agreement about these but I was thinking it may be good to clarify it in the documentation. So, I put together this PR to try to roughly codify the current convention as I understand it.

My understanding comes from these observations:

  • The 12.1. Syntax section of the Nixpkgs manual states

    Use lowerCamelCase for variable names, not UpperCamelCase.

    It also says

    TODO: naming of attributes in all-packages.nix?

  • In 12.2. Package naming it says

    Dashes in the package name should be preserved in new variable names, rather than converted to underscores (which was convention up to around 2013 and most names still have underscores instead of dashes) — e.g., http-parser instead of http_parser.

    which I've taken to hold also for package attribute names but I don't know if the above text actually states this. Especially considering the TODO mentioned previously.

  • The issue tracker includes some discussions about attribute naming and my feeling is that there is a general consensus that package attribute names should be hyphenated. See, e.g., Rename inotifyTools to inotify-tools #9456.

  • For NixOS modules I haven't been able to find any authoritative source for naming modules. Looking at the names in NixOS today it seems clear that camel case is used in general but the hyphenated style is used whenever a specific package is referenced.

    For example, we have services.dd-agent.jmxConfig (and interestingly also services.dd-agent.api_key).

  • I found one example of moving from a hyphenated to a "camelized" module name. Namely, programs.zsh: rename oh-my-zsh to ohMyZsh #26083, where programs.zsh.oh-my-zsh was aliased to programs.zsh.ohMyZsh. Are there further examples? This is relatively recent so would this indicate a emerging preference? In my PR I have followed the more common hyphenated style.

This attempts to briefly clarify the current naming conventions of
attribute names in `all-packages.nix` and module option names.
@eqyiel
Copy link
Contributor

eqyiel commented Nov 20, 2017

One example of lisp case being preferred over snake case: fd565ce#commitcomment-25726655 (although apparently it wasn't in master for long)

@eqyiel
Copy link
Contributor

eqyiel commented Dec 7, 2017

Kind of related: #30452 (comment)

@eqyiel
Copy link
Contributor

eqyiel commented Dec 11, 2017

This one goes from camel case to lisp case: 695027f#commitcomment-26188346

Edit: my bad, I only read the title, not the actual commit. The renaming is from nix to nix-unstable.

@rycee
Copy link
Member Author

rycee commented Dec 11, 2017

I'm not sure why the attribute name is nixUnstable and not nix-unstable. I guess there is some historical significance? My gut feeling is that the attribute name should be nix-unstable (with a nixUnstable entry in aliases.nix).

@rycee rycee mentioned this pull request Dec 15, 2017
8 tasks
@lukateras
Copy link
Member

lukateras commented Dec 15, 2017

I'm not sure why the attribute name is nixUnstable and not nix-unstable.

Because Unstable is not part of the package name, but our suffix. Versions of the same package typically have a suffix in camel case, e.g. chromiumDev, wineStaging, patchelfUnstable.

There are a few such suffixes separated by a dash or underscore, but camel case is most common.

@lukateras
Copy link
Member

lukateras commented Dec 15, 2017

I would prefer to 1) unify case in directory name, derivation name, and top-level attribute name, 2) use whatever upstream has come up with instead of inventing our own version of the name.

I believe that would make Nixpkgs much easier to work with, because no one would have to learn the attribute name in Nix, only the actual package name. Similarly, if someone wants to find an artifact in Nix store, they could use the same name. It also might improve searchability.

It would be simpler, too: there would be only one name instead of several that may or may not be different depending on the context.

Copy link
Member

@nbp nbp left a comment

Choose a reason for hiding this comment

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

(only looking at the option declaration part) This sounds ok to me, and I should not hold the review.

Apparently github does not give notifications when you have to do reviews.

@orivej
Copy link
Contributor

orivej commented Dec 17, 2017

@rycee This PR looks good, except that "The hyphenated style is preferred in all three package names.", while true, is not applicable to package naming because we don't choose the names of upstream packages.

@lukateras
Copy link
Member

lukateras commented Dec 21, 2017

@orivej I think the three package names are directory name, derivation name, and top-level attribute name. Upstream name (case, rather) seems to be ignored.

@orivej
Copy link
Contributor

orivej commented Dec 21, 2017

The quality that I optimize names for, and which I observe to be optimized for most often in Nixpkgs, is memorability: we choose the most natural name, the one we would type without looking it up online or searching through the list of available packages. It would also be the one most frequently used in discussions about or issues of the project; the name of the directory we would choose to store some files related to the project. Sometimes it differs from an official name in casing, but it does not differ in hyphens or underscores. Note that upstreams themselves use different case in different official names, e.g. Totem in the documentation and totem as the name of the repository, which makes the rule "use whatever upstream has come up with" difficult to follow for a lot of projects with non-lowercase official names. We definitely should be lowercasing the name if the repository name or the source archive name or any installed file or directory name is lowercased. SkypeExport is very exceptional in that it has the same camel case name in the repository, the executable, and discussions, which is why it may not follow the rule of thumb that the name is always lowercased.

@lukateras
Copy link
Member

lukateras commented Dec 23, 2017

I agree.

@oxij
Copy link
Member

oxij commented Dec 23, 2017 via email

@lukateras
Copy link
Member

For instance, I think the package arguments/options should be lispified too.

This is not the currently used convention. This pull request is more or less an unopinionated description of the currently used convention. And if one wants to change the convention itself, that should probably be separate from this pull request.

I admit I was wrong too, in my previous comment. I now also think that using dashed names for almost all attribute names except where it makes sense not to do so is a good idea, that our suffixes should be in camel case, like they currently are, and that camel case for options is nice and makes it easy to distinguish options from derivations.

Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

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

I've rebuilt both Nixpkgs and NixOS manuals and formatting looks good. Also this just describes the rules we already use anyway.

@lukateras lukateras merged commit 108f76c into NixOS:master Dec 23, 2017
@rycee rycee deleted the doc/naming branch December 26, 2017 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants