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

TEST: reformat all nix files with nixpkgs-fmt #121490

Closed

Conversation

domenkozar
Copy link
Member

@domenkozar domenkozar commented May 2, 2021

DO NOT MERGE

Testing #120832 with:

find . -name "*.nix" -exec $(nix-build -A nixpkgs-fmt)/bin/nixpkgs-fmt {} \;

@SuperSandro2000
Copy link
Member

Thanks for starting this. Let us know if you need some help or some build power to test something.

@Synthetica9
Copy link
Member

The commit message for the main commit here is crucial documentation that can't be changed afterwards; it is therefore critical to get this right. I'd propose something like:

treewide: format with nixpkgs-fmt

If you are seeing this in git blame, you have not set up .git-blame-ignore-revs properly. To do this, you need to run the following command once:

git config blame.ignoreRevsFile .git-blame-ignore-revs

This should work with all local tools.
For more information see [INFO URL].

The info URL is so we can give more information in the future.

@Mindavi
Copy link
Contributor

Mindavi commented May 2, 2021

I like the general idea of doing this.

However, there are some things I don't like about the current formatting:

  • I don't think comments should be reformatted; they sometimes contain nix expressions, which are now flattened by the formatter (or it should be more intelligent, but I think not formatting is better)
  • I saw something where multiple values were listed like below, and the formatting got weird

packageA,
# comment
packageB,
# comment

It was formatted to this:

packageA
, # comment
packageB
, # comment

The comments are really not great, the second thing is less of an issue, but I'd never manually format it like that.

(This was just with a brief look, haven't looked very long at this)

@grahamc
Copy link
Member

grahamc commented May 2, 2021

I agree it should leave comments alone. A good example is these docs:


  /* Specialized `assertMsg` for checking if val is one of the elements
     of a list. Useful for checking enums.
    of a list. Useful for checking enums.
     Example:
       let sslLibrary = "libressl"
       in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
       => false
       stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl"
    Example:
    let sslLibrary = "libressl"
    in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
    => false
    stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl"
     Type:
       assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
    Type:
    assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
  */

the flattening here is unfortunate.

@domenkozar
Copy link
Member Author

I like the general idea of doing this.

However, there are some things I don't like about the current formatting:

  • I don't think comments should be reformatted; they sometimes contain nix expressions, which are now flattened by the formatter (or it should be more intelligent, but I think not formatting is better)
  • I saw something where multiple values were listed like below, and the formatting got weird

packageA,

comment

packageB,

comment

It was formatted to this:

packageA
, # comment
packageB
, # comment

The comments are really not great, the second thing is less of an issue, but I'd never manually format it like that.

(This was just with a brief look, haven't looked very long at this)

That looks like nix-community/nixpkgs-fmt#243

@domenkozar
Copy link
Member Author

I wanted to open this to test that whole nixpkgs/NixOS still evals. Unfortunately master moves quite fast and conflicts arise as soon as something is merged. Is there a way to run the whole eval suite locally?

lib/asserts.nix Outdated Show resolved Hide resolved
@domenkozar domenkozar reopened this May 15, 2021
@domenkozar
Copy link
Member Author

Built nixpkgs-fmt from master and ran find . -name "*.nix" -exec /nix/store/askqcqa4mrblhpgyks60hxiph8c61haj-nixpkgs-fmt-1.2.0/bin/nixpkgs-fmt {} \; on fresh master.

@Mindavi
Copy link
Contributor

Mindavi commented May 15, 2021

This still doesn't look quite right:

https://github.com/NixOS/nixpkgs/pull/121490/files#diff-9a742acd363e7062932805c87186c92a025bef9d215fda52b8d46631691bbe9bR54-R62

But maybe that's intended, I'm not sure. It's not something I'd do by hand though.

But overall this looks a lot better to me!

@domenkozar
Copy link
Member Author

domenkozar commented May 16, 2021

Comma at the end of at the beginning is a debate I'd like to avoid here and what's important is that we can have either way as that is a lossless conversion.

Other things anyone can notice? Otherwise it seems like nixpkgs-fmt formats all files and eval checks pass. I've also tested that running it twice doesn't make any new modifications 🍿

@Ma27
Copy link
Member

Ma27 commented May 16, 2021

  • Does anybody have a smart idea what tool to use for a review? 😅 git show in a less seems quite painful already ^^
  • AFAICS also automagically created files are touched. Shouldn't we exclude these? (or fix the upstream tools)
  • According to the labels this would cause a full stdenv rebuild (and from the changes I've seen in pkgs/stdenv this seems correct). Given that this is likely a candidate for staging, are we sure that this will be ready on time before the branchoff (which is on friday IIRC, cc @NixOS/release-engineers )

@zowoq
Copy link
Contributor

zowoq commented May 16, 2021

AFAICS also automagically created files are touched. Shouldn't we exclude these? (or fix the upstream tools)

One auto-generated file looks like it is responsible for the majority of the diff in this PR.

 pkgs/development/haskell-modules/hackage-packages.nix
 1 file changed, 505371 insertions(+), 249022 deletions(-)

@asymmetric
Copy link
Contributor

Comma at the end of at the beginning is a debate I'd like to avoid here and what's important is that we can have either way as that is a lossless conversion.

@domenkozar

This would look better IMO:

{
  foo
  # comments about bar
, bar
}

I think it would be valid too? Not sure how feasible or easy though.

@stale
Copy link

stale bot commented Nov 16, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 16, 2021
@domenkozar domenkozar closed this Aug 22, 2022
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

9 participants