Applied suggestions[1] from @mweinelt and did a small refactor. [1]: https://github.com/NixOS/nixpkgs/pull/183772#issuecomment-1237014790