Is there an opensource/selfhosted alternative to obsidian?

It might not be a direct alternative, since it's not using markdown files directly, but I really like Trilium notes (https://github.com/zadam/trilium).

It's open source, you can selfhost it and you can write your own scripts in JS to really make it your own.