Skip to content

check-meta.nix: Add package warnings#338267

Closed
AkechiShiro wants to merge 2 commits intoNixOS:masterfrom
AkechiShiro:rfc127-implementation-test
Closed

check-meta.nix: Add package warnings#338267
AkechiShiro wants to merge 2 commits intoNixOS:masterfrom
AkechiShiro:rfc127-implementation-test

Conversation

@AkechiShiro
Copy link
Contributor

@AkechiShiro AkechiShiro commented Aug 29, 2024

Description of changes

Implements RFC 127 NixOS/rfcs#127
Adds testing for multiple cases

Should supersede : #177272

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 6.topic: stdenv Standard environment labels Aug 29, 2024
@AkechiShiro
Copy link
Contributor Author

I will rebase then work on solving conflicts, marking this PR as draft for now.

@AkechiShiro AkechiShiro marked this pull request as draft August 29, 2024 21:05
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 29, 2024
@AkechiShiro AkechiShiro force-pushed the rfc127-implementation-test branch 3 times, most recently from 03ea8fe to f56564b Compare August 30, 2024 07:02
@AkechiShiro AkechiShiro removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 30, 2024
@AkechiShiro AkechiShiro force-pushed the rfc127-implementation-test branch from f56564b to e9eff04 Compare August 30, 2024 23:20
@AkechiShiro AkechiShiro force-pushed the rfc127-implementation-test branch from e9eff04 to 1589696 Compare September 4, 2024 11:32
@ofborg ofborg bot added 8.has: clean-up This PR removes packages or removes other cruft 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Sep 4, 2024
@AkechiShiro AkechiShiro force-pushed the rfc127-implementation-test branch 3 times, most recently from a1269fe to 69b5584 Compare September 4, 2024 12:34
@AkechiShiro AkechiShiro marked this pull request as ready for review September 4, 2024 12:35
@infinisil infinisil requested a review from piegamesde September 4, 2024 12:48
++ lib.optionals (meta ? problems) (

# Check problem kinds are correct
lib.pipe meta.problems [
Copy link
Member

Choose a reason for hiding this comment

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

This all looks very allocation/iteration heavy:
I'd completely avoid using lib.pipe in any hot paths for one.

For a normal code review I wouldn't be so pedantic about this, but check-meta is a performance special case.
Changes here needs to be carefully measured, and the Ofborg performance report doesn't include checkMeta, so it's entirely useless in this context.

Measuring nixpkgs eval with checkMeta = true before and after this PR (env NIX_SHOW_STATS=1 nix-env -qa -f ./outpaths.nix --arg checkMeta true > /dev/null):

  • Before
{
  "cpuTime": 271.2768249511719,
  "envs": {
    "bytes": 7850426888,
    "elements": 413454253,
    "number": 283924554
  },
  "gc": {
    "heapSize": 22804639744,
    "totalBytes": 47139879824
  },
  "list": {
    "bytes": 987373624,
    "concats": 21648163,
    "elements": 123421703
  },
  "nrAvoided": 329081776,
  "nrFunctionCalls": 261979419,
  "nrLookups": 131336801,
  "nrOpUpdateValuesCopied": 675865734,
  "nrOpUpdates": 32046977,
  "nrPrimOpCalls": 146549876,
  "nrThunks": 399878601,
  "sets": {
    "bytes": 15552994336,
    "elements": 911935337,
    "number": 60126809
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 2887399,
    "number": 178950
  },
  "values": {
    "bytes": 12350285592,
    "number": 514595233
  }
}
  • After
{
  "cpuTime": 296.9483947753906,
  "envs": {
    "bytes": 8506454064,
    "elements": 438912624,
    "number": 312197067
  },
  "gc": {
    "heapSize": 22737526784,
    "totalBytes": 48902439376
  },
  "list": {
    "bytes": 1000276576,
    "concats": 22264431,
    "elements": 125034572
  },
  "nrAvoided": 349063893,
  "nrFunctionCalls": 289412278,
  "nrLookups": 149742381,
  "nrOpUpdateValuesCopied": 694111348,
  "nrOpUpdates": 35108342,
  "nrPrimOpCalls": 168992563,
  "nrThunks": 417292743,
  "sets": {
    "bytes": 15871244064,
    "elements": 927562812,
    "number": 64389942
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 4092168,
    "number": 234982
  },
  "values": {
    "bytes": 12774278736,
    "number": 532261614
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What could be used to have better performance whilst keeping the same or similar functionality ?

Copy link
Member

@adisbladis adisbladis Sep 5, 2024

Choose a reason for hiding this comment

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

  • Don't keep calling mapAttrsToList
    mapAttrsToList is attrs: map fn (attrNames attrs).
    You should store attrNames in a variable and keep reusing that

  • lib.remove null -> concatMap
    Nix has an optimisation for empty lists

The code below is a good simple example:

# Check that problem has a message (required field)
++ lib.pipe meta.problems [
  (lib.mapAttrsToList (    name: problem:
    if problem ? message then
      null
    else
      "key 'meta.problems.${name}.message' is missing"
    ))
    (lib.remove null)
]

->

let
  # Stick this in the outermost scope where it makes sense
  problemNames = attrNames meta.problems;
in
  # Nix has an optimisation for returning empty lists
  # And another optimisation for lists with <= 2 elements
  concatMap (name: if meta.problems.${name} ? message then [] else [ "key 'meta.problems.${name}.message' is missing" ])

Copy link
Member

@adisbladis adisbladis Sep 5, 2024

Choose a reason for hiding this comment

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

And just in general: Read the lib implementations you're using here and understand that Nix is not very optimised.
Sadly we don't have good guidance on how to write performant Nix code.
NIX_SHOW_STATS=1 is your friend.

# Check that some problem kinds are unqiue
++ lib.pipe meta.problems [
(lib.mapAttrs (name: problem: { kind = name; } // problem))
# Count the number of instances of each problem kind,
Copy link
Member

Choose a reason for hiding this comment

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

I think the manual counting & checking is better implemented by combining groupBy & concatMap over problemKindsUnique'.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 10, 2024
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 25, 2025
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. and removed 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Nov 26, 2025
infinisil added a commit to tweag/nixpkgs that referenced this pull request Dec 2, 2025
- Makes the code more clean and obvious
- Allows remediations to depend on values computed during the check
  (useful for NixOS#338267)
@infinisil infinisil force-pushed the rfc127-implementation-test branch 3 times, most recently from bbcf3e3 to dcc4587 Compare December 2, 2025 18:55
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. labels Dec 2, 2025
@infinisil infinisil force-pushed the rfc127-implementation-test branch from af94fab to 4a1fdd9 Compare December 2, 2025 22:07
infinisil added a commit to tweag/nixpkgs that referenced this pull request Dec 15, 2025
- Makes the code more clean and obvious
- Allows remediations to depend on values computed during the check
  (useful for NixOS#338267)

Reapplying 42cfcdf
after reversal in 0b90ed8

Compared to the original commit, this includes the fix for the problem
that required the revert.
barsikus007 pushed a commit to barsikus007/nixpkgs that referenced this pull request Dec 16, 2025
- Makes the code more clean and obvious
- Allows remediations to depend on values computed during the check
  (useful for NixOS#338267)

Reapplying 42cfcdf
after reversal in 0b90ed8

Compared to the original commit, this includes the fix for the problem
that required the revert.
@infinisil infinisil force-pushed the rfc127-implementation-test branch 2 times, most recently from d5de905 to d007542 Compare December 23, 2025 16:49
@infinisil
Copy link
Member

I've now optimised this as far as I think is reasonably possible. Performance is still a bit worse than before, but much better now. Check the automatic performance report for details.

I've also adjusted the error messages slightly, while making sure that the tests still pass.

Now the only thing that's left imo are:

  • Clean up the code and address some TODOs
  • Make sure RFC 127 actually works out well in practice, not sure if that was ever done before

Run with `nix-build -A tests.problems`

RFC 127: Add implementation tests

* Also fix merge conflicts
* Make sure that performance PR is conserved
* Use RunCommand instead of alias RunCommandNoCC
* Add enum types to meta-types.nix and use them for problemTypes
* Nixfmt (excepted check-meta.nix)
* "import" elem
* Remove dead code

Co-Authored-By: piegames <[email protected]>
Co-Authored-By: AkechiShiro <[email protected]>
Co-Authored-By: Silvan Mosberger <[email protected]>

[WIP] Fast problem handler lookup switch

Disable problem check for testing

Better perf
@infinisil infinisil force-pushed the rfc127-implementation-test branch from d007542 to 1af96fe Compare January 5, 2026 23:15
@infinisil infinisil force-pushed the rfc127-implementation-test branch from 5cd767e to fecb526 Compare January 9, 2026 18:21
@infinisil
Copy link
Member

infinisil commented Jan 9, 2026

At this point I think it makes sense to open a new PR. Will do so shortly with the latest changes and advertise it for people to try out and give feedback :)

Edit: #478539

@infinisil infinisil closed this Jan 9, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Done in Stdenv Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: stdenv Standard environment 8.has: clean-up This PR removes packages or removes other cruft 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants