Executable output of `toFile`

I am configuring dunst through home manager and attempting to add a script to play a notification sound.

The current configuration is as follows:

home-manager.users.me.services.dunst.settings.play_sound.script = builtins.toFile "sound.sh" ''
  #! /usr/bin/env sh
  if [[ "$1" == "changeVolume" ]]; then
    return 0
  fi

  /run/current-system/sw/bin/mpv /run/current-system/sw/share/sounds/freedesktop/stereo/bell.oga --really-quiet
'';

This does everything right except the lack of executable permissions on the written file. My question: is there either a way to modify the permissions of the file after using toFile or an alternative function to use in place of toFile that allows the specification of permissions?

P.S. I know the script’s use of /run/current-system/sw/... isn’t the best way to do it; it’s like that for simplification during testing.

Yes, you can use pkgs.writeScript

I tried using that before and got ... is not of type 'string or boolean or signed integer or list of string'., so I assumed it was the wrong thing to use. As per your reply I tried it again, realising it just needed bulitins.toString applied to it seeing as it returns a path (which I though builtins.toFile did, hence why I gave up on using pkgs.writeScript in the first place). Thanks for your answer.