Is it possible to set systemd environment variables from a recipe to do the same as 'systemctl set-environment SOME_ENV_VAR' on target?
Your recipe could install a systemd.conf.d file to set the DefaultEnvironment
option, e.g.
customrecipe/files/defaultenv.conf
[Manager] DefaultEnvironment=CUSTOMENV=42
customrecipe/customrecipe.bb
SUMMARY = "Example Recipe" LICENSE = "CLOSED" SRC_URI = "file://defaultenv.conf" do_install() { install -m 0755 -d ${D}${systemd_unitdir}/system.conf.d install -m 0755 ${WORKDIR}/defaultenv.conf ${D}${systemd_unitdir}/system.conf.d/90-defaultenv.conf } FILES_${PN} += "${systemd_unitdir}/system.conf.d"
This has the same effect as running systemctl set-environment CUSTOMENV=42
at runtime, and you can verify it using systemctl show-environment
.
However, if the environment variable only needs to be set for the systemd units that the recipe is already installing, it would be more appropriate to modify the unit file (directly or using sed -i
) to set the Environment
option in the [exec]
section.