# We added a linter to Nixpkgs checking workflows

**URL:** https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722
**Category:** Announcements
**Created:** [July 27, 2024, 2:32pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722 "2024-07-27T14:32:45Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 2:32pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/1 "2024-07-27T14:32:45Z")

</div>

This linter, [nixf](https://github.com/nix-community/nixd/tree/main/libnixf) is part of [nixd](https://github.com/nix-community/nixd), a nix language server. By using it, we will output the same diagnostic message as nixd, mainly:

1. Better parsing error in some cases, like missing semicolon and unexpected character at line end
2. Unused code, like arguments, variables, `rec`, `with`, etc
3. ~~Escaping `with` (use of external variables inside with, which can easily cause ambiguity). This can be part of avoiding overuse of `with`.~~ (This may be postponed until we reach consensus on handling `with` in many aspects)

By using GitHub’s [workflow message feature](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message), we render it in ‘Files changed’ overview, directly below the lines with errors. You can check an example here: [workflows/check-nixf-tidy.yml: by Aleksanaa · Pull Request #1 · Aleksanaa/nixpkgs · GitHub](https://github.com/Aleksanaa/nixpkgs/pull/1/files) (But there are going to be more examples popping up in Nixpkgs lol)

This workflow is the same as the checking format one, and will only check files that did not have problems in the past, as well as newly created files. But after a few rounds of treewide, we can minimize the existing files with problems, so hopefully we will get a cleaner codebase.

This feature is still in the experimental stage, and may encounter edge cases or areas where people are dissatisfied. Feel free to remind me (`@Aleksanaa`) and `@inclyc` under PR where problem occurs. We will actively fix these issues and focus on future improvements.

This workflow can also be provided as a separated GitHub action in the future to enpower other similar projects at the same time. If anyone would like to do this, they are more than welcome.

Many thanks to @inclyc for developing such a powerful tool, and @Infinisil for telling me this very crucial GitHub feature that makes it work like a charm!

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 2:33pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/2 "2024-07-27T14:33:13Z")

</div>

Original PR is here: [workflows/check-nixf-tidy.yml: init by Aleksanaa · Pull Request #330066 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/330066)

---

<div class="post-metadata">

### Author: ![Sigmanificient](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sigmanificient/32/10706_2.png) [@Sigmanificient](https://discourse.nixos.org/u/Sigmanificient)
#### Post date: [July 27, 2024, 2:35pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/3 "2024-07-27T14:35:45Z")

</div>

yay‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌!

---

<div class="post-metadata">

### Author: ![gador](https://discourse.nixos.org/user_avatar/discourse.nixos.org/gador/32/6272_2.png) [@gador](https://discourse.nixos.org/u/gador)
#### Post date: [July 27, 2024, 2:53pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/4 "2024-07-27T14:53:00Z")

</div>

This is seriously cool!

---

<div class="post-metadata">

### Author: ![Nebucatnetzer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nebucatnetzer/32/5770_2.png) [@Nebucatnetzer](https://discourse.nixos.org/u/Nebucatnetzer)
#### Post date: [July 27, 2024, 4:32pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/5 "2024-07-27T16:32:24Z")

</div>

This is great!  
I seriously love it when I don’t have to think about the specific formats and conventions when contributing to a project.

Would it make sense to add it to shell.nix like the formatter?

> <https://github.com/NixOS/nixpkgs/blob/933c3874106e919094da93d2eabec3bf8ffb2923/shell.nix>

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 4:35pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/6 "2024-07-27T16:35:57Z")

</div>

> [@Nebucatnetzer](#):
>
> Would it make sense to add it to shell.nix like the formatter?

Maybe I should write a wrapper to achieve a similar effect to deadnix. The current rendering is implemented using a jq expression, which may be a bit lame in our toolbox because I need to write another jq expression to make it more human friendly

---

<div class="post-metadata">

### Author: ![inclyc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inclyc/32/10485_2.png) [@inclyc](https://discourse.nixos.org/u/inclyc)
#### Post date: [July 27, 2024, 5:00pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/7 "2024-07-27T17:00:15Z")

</div>

Maybe just use `nixd` the language server, it shares the frontend with nixf-tidy, and we don’t need worry about rendering because diagnostics are rendered on man’s favorite editor.

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 5:03pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/8 "2024-07-27T17:03:20Z")

</div>

Good point, now we’re brewing another epic editor war 😅

---

<div class="post-metadata">

### Author: ![pbsds](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbsds/32/11198_2.png) [@pbsds](https://discourse.nixos.org/u/pbsds)
#### Post date: [July 27, 2024, 5:29pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/9 "2024-07-27T17:29:43Z")

</div>

Unused code shouldn’t block PRs, imagine all the r-ryantm PRs that would stall. Is it possible to turn them into warnings rather than errors?

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 5:31pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/10 "2024-07-27T17:31:16Z")

</div>

> [@pbsds](#):
>
> imagine all the r-ryantm PRs that would stall.

Files that had errors before editing will be temporarily skipped. For files without problems, r-ryantm will not corrupt them.

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 5:32pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/11 "2024-07-27T17:32:29Z")

</div>

> [@pbsds](#):
>
> Unused code shouldn’t block PRs

We should set stricter rules for this. Of course, it is OK to output them in a different color, but I tend to think that this is an error for us, so let’s output it in the error color.

---

<div class="post-metadata">

### Author: ![Artturin](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Artturin](https://discourse.nixos.org/u/Artturin)
#### Post date: [July 27, 2024, 5:34pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/12 "2024-07-27T17:34:57Z")

</div>

Can these kinds of lints be added [nixpkgs-lint/src/queries.rs at e3a0489204a5db0cd806c26ddecb608da59072a0 · nix-community/nixpkgs-lint · GitHub](https://github.com/nix-community/nixpkgs-lint/blob/e3a0489204a5db0cd806c26ddecb608da59072a0/src/queries.rs)

---

<div class="post-metadata">

### Author: ![pbsds](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbsds/32/11198_2.png) [@pbsds](https://discourse.nixos.org/u/pbsds)
#### Post date: [July 27, 2024, 5:35pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/13 "2024-07-27T17:35:58Z")

</div>

Neat, i’m still unsure but lets see how it goes. My greatest fear is that we end up unable to merge the plethora of otherwise good drive-by contributions whose authors are often unresponsive to review feedback.

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 27, 2024, 5:45pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/14 "2024-07-27T17:45:15Z")

</div>

> [@pbsds](#):
>
> My greatest fear is that we end up unable to merge the plethora of otherwise good drive-by contributions whose authors are often unresponsive to review feedback

We can’t do anything about this, for example, they don’t format, write non-standard commit messages (I can still tolerate this, using squash merge). In this case, there is no difference between the reviewer pointing out that there is an unused variable and CI pointing out it, and the latter is even more efficient.

Of course they should not be bothered by existing errors, because the files with errors before editing will be ignored. If their submission is an important fix but they made some mistakes, there will be a committer to help them deal with it.

---

<div class="post-metadata">

### Author: ![inclyc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inclyc/32/10485_2.png) [@inclyc](https://discourse.nixos.org/u/inclyc)
#### Post date: [July 28, 2024, 6:52am UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/15 "2024-07-28T06:52:17Z")

</div>

Yes absolutely we can do, these checks are specific to nixpkgs, maybe introduced under a CLI flag.

---

<div class="post-metadata">

### Author: ![linj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/linj/32/27480_2.png) [@linj](https://discourse.nixos.org/u/linj)
#### Post date: [July 28, 2024, 7:34am UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/16 "2024-07-28T07:34:17Z")

</div>

> [@Aleksanaa](#):
>
> files with errors before editing will be ignored

`elpa.nix` has unused varables, such as `version`, before a [PR](https://github.com/NixOS/nixpkgs/pull/330589). Yet, this file is not ignored.

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 28, 2024, 8:25am UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/17 "2024-07-28T08:25:53Z")

</div>

That’s @inclyc’s bot, not the workflow

---

<div class="post-metadata">

### Author: ![inclyc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inclyc/32/10485_2.png) [@inclyc](https://discourse.nixos.org/u/inclyc)
#### Post date: [July 28, 2024, 10:54am UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/18 "2024-07-28T10:54:49Z")

</div>

Yes, that was another implementation which based on errors occurred on git-diff, it’s a little more chatty and based on PR reviews (not CI comments).

---

<div class="post-metadata">

### Author: ![GetPsyched](https://discourse.nixos.org/user_avatar/discourse.nixos.org/getpsyched/32/11910_2.png) [@GetPsyched](https://discourse.nixos.org/u/GetPsyched)
#### Post date: [July 28, 2024, 11:34am UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/19 "2024-07-28T11:34:57Z")

</div>

> [@Aleksanaa](#):
>
> Of course they should not be bothered by existing errors, because the files with errors before editing will be ignored.

Regarding this, I’m willing to sit down, run the linter on all packages, and fix them one by one. I could do this as a chore for about 10 minutes daily or such. It would take months depending on how many packages “break”, but I guess once it’s all cleared up, the CI wouldn’t need to try and ignore existing issues.

Nevertheless, I’m not sure how much of this is worth than putting my time towards something considered more important.

---

<div class="post-metadata">

### Author: ![Aleksanaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aleksanaa/32/12953_2.png) [@Aleksanaa](https://discourse.nixos.org/u/Aleksanaa)
#### Post date: [July 28, 2024, 6:11pm UTC](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722/20 "2024-07-28T18:11:33Z")

</div>

> [@GetPsyched](#):
>
> Regarding this, I’m willing to sit down, run the linter on all packages, and fix them one by one.

Oh also, although my CI does not extract it, nixf-tidy actually includes the suggested fix information which can be processed with a script. It currently does not support unused variables, but that should also be trivial.

[Next page](https://discourse.nixos.org/t/we-added-a-linter-to-nixpkgs-checking-workflows/49722.md?page=2)
