Build time option to retain X snap revisions

Currently a user can set the number of snap revisions that should be kept on the system in case an update goes bad etc.

The command is

snap set system refresh.retain=2

I wonder if there is a build-time flag that I could use while compiling snapd to have that config set by default ?

There is not a flag when building snapd, but you can set this value via your gadget snap defaults in the gadget.yaml.

If you do not care about reexec, as last resort, you can patch it during the build. The relevant bits are here: