If you do it via /admin/customize/robots it will persist.
/admin/customize/robots
It gets stored in a hidden site setting called overridden_robots_txt. If that’s filled it will always be served as your robots.txt file.
overridden_robots_txt