I went down the rabbit hole of an open source replacement for notion earlier today randomly.
Obsidian is very solid and has a huge addon eco system to change it most ways you might thino of.
AnyType is lying about open source, it is just “source available”, as their licence call it: https://github.com/anyproto/anytype-ts/blob/main/LICENSE.md You can see the source, but the licence restrict you from any commercial use, even if you want to use AnyType in a company.
I can recommend Notesnook. Relatively cheap premium plan, everything is open source, with clients available on F-Droid and Flatpak and end-to-end encryption.
For server code they already published the source. Option to use self-hosted servers is on the roadmap: https://notesnook.com/roadmap/