How exactly does home-manager transform alias values?

I tend to use a lot of sed, so, for instance, when I want to change to nerdy wallpapers, I’ll use this command aliased in my bashrc which changes the directories referenced in the script which a systemd service uses to shuffle my wallpaper
alias wallnerd=“sed ‘s/HorWallpapers=.$/HorWallpapers=($(realpath /home/horsey/Pictures/Backgrounds/1/* | shuf -n 2))/ ; s/VerWallpapers=.$/VerWallpapers=($(realpath /home/horsey/Pictures/Backgrounds/5/* | shuf -n 1))/’ -i /home/horsey/bin/randwall; systemctl --user start hyprpaperrand.service”

however, if I set
wallnerd = "sed 's/HorWallpapers=.*$/HorWallpapers=(\$(realpath \/home\/horsey\/Pictures\/Backgrounds\/1\/\* | shuf -n 2))/ ; s/VerWallpapers=.*$/VerWallpapers=(\$(realpath \/home\/horsey\/Pictures\/Backgrounds\/5\/\* | shuf -n 1))/' -i /home/horsey/bin/randwall; systemctl --user start wallpaper-shuffle.service";

in home-manager.programs.bash.shellAliases and trigger ‘wallnerd’ I recieve
~ ❯ wallnerd
sed: -e expression #1, char 48: unknown option to `s’

If I edit the above expression. throw another backslash in front of the first forward slash, rebuild, and open a new shell I receive

~ ❯ wallnerd
sed: -e expression #1, char 54: unknown option to `s’

but other simpler alias work as expected
hgrep = “history | grep $1”;
~ ❯ hgrep arbitrary
2028 04/30/26 14:58:18 echo “this is an arbitrary string”
2029 04/30/26 14:58:24 hgrep arbitrary
To be clear, I do not need help changing my wallpapers, there are lots of obvious solutions, but I would like to understand the specific ways in which home-manager/nix is transforming values passed into it. Can someone point me in the right direction?