Skip to content

lib/modules: Reject extra attributes on properties#394852

Draft
roberth wants to merge 3 commits intoNixOS:masterfrom
roberth:modules-strict-properties
Draft

lib/modules: Reject extra attributes on properties#394852
roberth wants to merge 3 commits intoNixOS:masterfrom
roberth:modules-strict-properties

Conversation

@roberth
Copy link
Member

@roberth roberth commented Mar 31, 2025

... because they would be ignored, and their presence is probably a (easy) user mistake.

This reduces our forward compatibility, but I doubt that we need any here, and I doubt that the forward compatibility behavior should be anything other than an error anyway.

TODO

  • benchmark
  • tests
  • something similar for mkOverride

Context:
I'm using a lambda call to perform this check with minimal function calls. This should reduce allocations and time spent (unconfirmed) at a small penalty in terms of error message quality. I believe this would be the right trade-off.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

... because they would be ignored, and their presence is probably
a user mistake.

This reduces our forward compatibility, but I doubt that we need
any here, and I doubt that the forward compatibility behavior
should be anything other than an error anyway.
@roberth roberth added the 6.topic: module system About "NixOS" module system internals label Mar 31, 2025
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Mar 31, 2025
@roberth roberth marked this pull request as draft March 31, 2025 09:19
@nix-owners nix-owners bot requested review from hsjobeki and infinisil March 31, 2025 09:20
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 31, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Mar 31, 2025
Copy link
Contributor

@hsjobeki hsjobeki left a comment

Choose a reason for hiding this comment

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

Looking lgtm to me.

Would be nicer to throw a better error message if an unsuppported propery is passed.
Attribute not found isn't quite describing the error if a person run into this error.

@hsjobeki
Copy link
Contributor

hsjobeki commented Apr 1, 2025

This should reduce allocations and time spent

This should be able to publicly confirm soon:
#395113

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 2, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: lib The Nixpkgs function library 6.topic: module system About "NixOS" module system internals 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 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.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants