There is useful info in a closed Set default cloud-init - #2 by cgrabowski, but the best explanation is in https://ubuntu.com/blog/customising-maas-installs to use curtin --in-target --
.
I ended up with the following customization and I hope it helps the next person:
$ cat /etc/maas/preseeds/curtin_userdata
#cloud-config
debconf_selections:
maas: |
{{for line in str(curtin_preseed).splitlines()}}
{{line}}
{{endfor}}
early_commands:
{{if third_party_drivers and driver}}
...
{{endif}}
write_files:
install_packages:
path: /home/ubuntu/install_packages.sh
permissions: '0755'
content: |
#!/bin/bash
set -eu
DEBIAN_FRONTEND=noninteractive
GENERIC_PACKAGES=(python3-pip)
sudo DEBIAN_FRONTEND=${DEBIAN_FRONTEND} apt-get install --verbose-versions ${GENERIC_PACKAGES[@]} -y
late_commands:
maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
install_nvidia_drivers: curtin in-target -- bash -x /home/ubuntu/install_packages
{{if third_party_drivers and driver}}
...
{{endif}}