From ca4a5e1f20551bf8069095410ea2c9db1aab5a1e Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 26 Jul 2024 00:33:32 +0200 Subject: [PATCH 1/2] CONTRIBUTING.md: Editorconfig instead of manual description --- CONTRIBUTING.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44d88a1653053..67972d21fd12a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -557,9 +557,7 @@ Names of files and directories should be in lowercase, with dashes between words ### Syntax -- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. - -- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use `(setq-default indent-tabs-mode nil)` in Emacs. Everybody has different tab settings so it’s asking for trouble. +- Set up [editorconfig](https://editorconfig.org/) for your editor, such that [the settings](./.editorconfig) are automatically applied. - Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [package naming](./pkgs/README.md#package-naming). From 8121f5a4bddf5efde3223a3da44b8999d2f081a0 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 26 Jul 2024 00:37:12 +0200 Subject: [PATCH 2/2] CONTRIBUTING.md: Mention nixfmt instead of manual formatting rules --- CONTRIBUTING.md | 127 +----------------------------------------------- 1 file changed, 1 insertion(+), 126 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67972d21fd12a..8d99e465cc0ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -561,132 +561,7 @@ Names of files and directories should be in lowercase, with dashes between words - Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [package naming](./pkgs/README.md#package-naming). -- Function calls with attribute set arguments are written as - - ```nix - foo { - arg = <...>; - } - ``` - - not - - ```nix - foo - { - arg = <...>; - } - ``` - - Also fine is - - ```nix - foo { arg = <...>; } - ``` - - if it's a short call. - -- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned: - - ```nix - { - # A long list. - list = [ - elem1 - elem2 - elem3 - ]; - - # A long attribute set. - attrs = { - attr1 = short_expr; - attr2 = - if true then big_expr else big_expr; - }; - - # Combined - listOfAttrs = [ - { - attr1 = 3; - attr2 = "fff"; - } - { - attr1 = 5; - attr2 = "ggg"; - } - ]; - } - ``` - -- Short lists or attribute sets can be written on one line: - - ```nix - { - # A short list. - list = [ elem1 elem2 elem3 ]; - - # A short set. - attrs = { x = 1280; y = 1024; }; - } - ``` - -- Breaking in the middle of a function argument can give hard-to-read code, like - - ```nix - someFunction { x = 1280; - y = 1024; } otherArg - yetAnotherArg - ``` - - (especially if the argument is very large, spanning multiple lines). - - Better: - - ```nix - someFunction - { x = 1280; y = 1024; } - otherArg - yetAnotherArg - ``` - - or - - ```nix - let res = { x = 1280; y = 1024; }; - in someFunction res otherArg yetAnotherArg - ``` - -- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e. - - ```nix - { arg1, arg2 }: - assert system == "i686-linux"; - stdenv.mkDerivation { /* ... */ } - ``` - - not - - ```nix - { arg1, arg2 }: - assert system == "i686-linux"; - stdenv.mkDerivation { /* ... */ } - ``` - -- Function formal arguments are written as: - - ```nix - { arg1, arg2, arg3 }: { /* ... */ } - ``` - - but if they don't fit on one line they're written as: - - ```nix - { arg1, arg2, arg3 - , arg4 - # Some comment... - , argN - }: { } - ``` +- New files must be formatted by entering the `nix-shell` from the repository root and running `nixfmt`. - Functions should list their expected arguments as precisely as possible. That is, write