What are some ways one might implement a more story-driven spell/skill acquisition?

What are some ways one might implement a more story-driven spell/skill acquisition? Hopefully in a way that isn’t a complete slog.

The idea of the players’ handbook being used as a shopping catalogue kinda ruins the immersion for me. It doesn’t make much sense that a character can go to sleep one day and then wake up the next suddenly knowing a bunch of new spells or skills if they happened to reach a new level. Especially that often those spells/skills have nothing to do with any in-game actions or backstory of the character. I’d love to see a game where the characters have to actively work towards acquiring their skills, and not just waiting till they’ve passed the next level threshold.

The question is largely about how a DnD5e system might get modified to fit my concerns because I don’t really have a group yet and 5e players are easiest to find. That said I’m open to hearing about other game systems.

In the context of 5e I was thinking of flipping the relationship between levels and skills/spells on its head and not have levels grant you skills but rather the achieving skills bumping your level up (at GM’s discretion). By "achieving skills" the character pursuing an RP way to acquire a skill. Depending on what’s going on in-game it might be super easy for some skills (e.g. you find that move that you’ve been trying to do all this time suddenly just works after enough practice) or verging on impossible for others (e.g. getting an ice-y spell for a character who is all about fire stuff). I imagine this could create a greater sense of anticipation and, ultimately, reward at the advancement of characters. Or I might be completely wrong and it’s only going to scare off potential players who just want to minmax.