I have not used it but this might be what you are looking for: https://github.com/nix-community/NixOS-WSL
You could also install the nix package manager on Ubuntu.
There are some quirks, and WSL2 is buggy enough that I would advise advanced Linux users to prefer a bare metal install or a normal VM if those will work at all.
That said, I've used the linked NixOS image under WSL every day at work for about a year, and I've been very glad to have it.
Standalone Nix also works well under WSL2. I semi-regularly use it that way as well, on Ubuntu and openSUSE, for some testing at work.
Right now I’m using Ubuntu, and it’s awesome, with the obvious caveats, but I am Nix-curious for quite a while and would love to give it a spin in that way if it were reasonably doable. Especially to help friends who are less technical easily install all of the things, it could be a game changer.
Edit: https://github.com/nix-community/NixOS-WSL
https://news.ycombinator.com/item?id=32173111