Skip to content

Fix/deprecate freeform type bad type#439189

Draft
roberth wants to merge 3 commits intoNixOS:masterfrom
roberth:fix-deprecate-freeformType-bad-type
Draft

Fix/deprecate freeform type bad type#439189
roberth wants to merge 3 commits intoNixOS:masterfrom
roberth:fix-deprecate-freeformType-bad-type

Conversation

@roberth
Copy link
Member

@roberth roberth commented Sep 1, 2025

I believe this provides a clearer fix with fewer workarounds.

We may further simplify this by removing the first commit, which is a very niche corner case that might not even help anyone.

TODO

  • tests

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@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. 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Sep 1, 2025
lib/types.nix Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"deprecation warning: while accessing option ${showOption loc}: (t.merge.v2 defs).value must only be accessed when `.headError == null`. This is a bug in code that consumes a module system type."
"deprecation warning: while accessing option ${showOption loc}: (t.merge.v2 defs).value must only be accessed when `.headError == null`. This means the type is incorrect and will throw an error on the next release."

Or something like this. "a bug in code that consumes a module system type" isn't really actionable.
As a user i would like to know that i need to fix my type. This gives the impression that there is nothing to be done from a users side.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a niche warning that only triggers if users call it in other circumstances than freeformType.
The other message gets triggered for that.
See my commit messages.

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.

I'm not sure if we should print non-actionable error/warning messages

@roberth roberth dismissed hsjobeki’s stale review September 1, 2025 15:22

Please read my comment and/or commit messages

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.

I think i am in favor of this solution rather than #438558. The risk of changing merge further is currently to big, and feels a bit rushed, while this is the correct solution. Use mergeDefinitions fixing the merge behavior of freeform.

But also changing the freeform merge has the risk to reveal other regressions. That relied on freeform beeing unchecked.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/breaking-changes-announcement-for-unstable/17574/97

@roberth roberth changed the title Fix deprecate freeform type bad type Fix/deprecate freeform type bad type Sep 2, 2025
@roberth roberth force-pushed the fix-deprecate-freeformType-bad-type branch from 83e749e to 8a99203 Compare September 2, 2025 10:13
This helps users fix their code.
Found in NixOS#438459
A nicer fix for the freeformType comes in the next commit.
…te bad types

Allow bad types (not in attrsOf) to be used in freeformType again, but
add a deprecation message.

lib.either is special-cased, because it provides a less useful message
for its own problem, which is best to ignore when that occurs in
a freeformType.
@roberth roberth force-pushed the fix-deprecate-freeformType-bad-type branch from 8a99203 to c58629c Compare September 2, 2025 10:14
This way we avoid blasting users with a ton of useless context many times in the
same eval.
@hsjobeki
Copy link
Contributor

hsjobeki commented Sep 4, 2025

I think i am a bit afraid of this PR could change the semantics of freeformType

Maybe we should reconsider a two step solution? enabling check for freeformType could introduce more hidden regressions.
These bad usages of freeformType are all over nixpkgs.

Step 1 could be to just remove the abort in the magical either case for now.
Its less invasive to the merge behavior of freeformTypes

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 14, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 4, 2026
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 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