Possibility to save SPM batch scripts via nipype?

I would like to use nipype to run a first- and second-level-analysis via SPM. I wonder if there is a possibility to save the SPM-batch scripts that are generated in the background from nipype?

Answering my own question here (for now, so no guarantee that the following is correct): Yes, that is possible, e.g. Level1Design outputs a SPM.mat file which one can save using a DataSink Node or simply by defining a base_dir for your workflow (which will save also save the outputs of Level1Design).

Have a look at this part of the nipype_tutorial.

However, if you are running your workflow within a Docker or Singularity Container and you are interested in saving the SPM.mat file in such a way, that others who don’t have access to nipype and/or want to rerun the analysis solely using SPM, you (or users after you, who want to use your settings) probably need to post-hoc adapt the SPM.mat file.

If this is not important for you, you can still load in SPM to have a look at the design matrix, your settings for the First-Level-Model, etc. but you can’t execute this SPM.mat file using bare-metal SPM unless you change the paths of the images to files that actually locally exist on your hard drive (possibly by tweaking the SPM.xY.P in your SPM.mat file using a MATLAB script (which you can also run within nipype)

You might want to have a look at this question where this problem is addressed.