More official guidelines in regards to styling choices

A bit late but since this pr by infinisil got recently merged, I figure I’d raise a question about stylistic choices that exist beyond nixfmt’s scope.

Something I see often between various packages is the inconsistency of mkDerivation rec {} vs mkDerivation (finalAttrs: {}). This actually was the main thing that prompted me to ask this question and raise it to the community. Do we have stable and consistent documentation detailing a preferred style for packages in nixpkgs? I think if not it would be great to make it a more prominent discussion now that we are overall becoming more serious about formatting across the board.

To the community I also raise another question, maybe this can serve as a place of discussion; are there other inconsistencies in nixpkgs that you find should be relevant in this scope and brought to attention?

finalAttrs has better properties generally, if you need self-references.

These two patterns have distinct use-cases. The preferred style depends on the use-case.

See Documentation: guide for using `let in` vs `rec` vs `finalAttrs` · Issue #315337 · NixOS/nixpkgs · GitHub

7 Likes

This was a good read, especially eye opening to see how finalAttrs propagates differently than rec. I definitely agree that strict and concise documentation about how these different choices can propagate differently.

Parts of it started with the old anti-patterns page, now called Best Practices:

https://nix.dev/guides/best-practices.html

I am a type of stubborn evangelist of this guide, and many of its advices were proved true.

(future updates here)

1 Like