The answer depends on whether the variable is supposed to be constant (that is, not supposed to be modified by user getting the unit) or variable (supposed to be set by the user).
Since it's your local unit, the boundary is quite blurry and either way would work. However, if you started to distribute it and it would end up in /usr/lib/systemd/system, this would become important.
Constant value
If the value doesn't need to change per instance, the preferred way would be to place it as Environment=, directly in the unit file:
[Unit]
Description=My Daemon
[Service]
Environment="FOO=bar baz"
ExecStart=/bin/myforegroundcmd
[Install]
WantedBy=multi-user.target
The advantage of that is that the variable is kept in a single file with the unit. Therefore, the unit file is easier to move between systems.
Variable value
However, the above solution doesn't work well when sysadmin is supposed to change the value of the environment variable locally. More specifically, the new value would need to be set every time the unit file is updated.
For this case, an extra file is to be used. How — usually depends on the distribution policy.
One particularly interesting solution is to use /etc/systemd/system/myservice.service.d directory. Unlike other solutions, this directory is supported by systemd itself and therefore comes with no distribution-specific paths.
In this case, you place a file like /etc/systemd/system/myservice.service.d/local.conf that adds the missing parts of unit file:
[Service]
Environment="FOO=bar baz"
Afterwards, systemd merges the two files when starting the service (remember to systemctl daemon-reload after changing either of them). And since this path is used directly by systemd, you don't use EnvironmentFile= for this.
If the value is supposed to be changed only on some of the affected systems, you may combine both solutions, providing a default directly in the unit and a local override in the other file.
sysconfigpath is specific to Fedora but the question is about Arch Linux. The answer by paluh is more interesting I think – Ludovic Kuty Apr 27 '13 at 08:49/etc/sysconfigis Fedora-specific. AFAIR Arch Linux was pushing for having the config files somewhere package-specific rather in/etcrather than that Fedora-specific location. Like/etc/myservice.conf, though using extra file doesn't seem the right way here. – Michał Górny Apr 23 '14 at 07:13/etc/conf.d. Some inspection of existing unit files should reveal the directory it uses. – Michael Hampton Aug 01 '14 at 21:12DJANGO_SETTINGS_MODULE=project.settings, one per line. – Michael Hampton Nov 02 '15 at 17:01blahservice, can I also use the/etc/systemd/system/blah.service.d/blah.conffile to passEnvironment=stuff to myblahservice? – Felipe Alvarez Nov 03 '16 at 05:15Environment=to pass secrets like passwords. See my answer for details. – Don Kirkby May 04 '18 at 00:30EnvironmentoverEnvironmentFile. And given theEnvironment='s values being visible to all withsystemctl show, as explained in @DonKirby's answer, it seems to me thatEnvironmentFileis much better. – Davor Cubranic Feb 07 '23 at 21:04Environment=EV=? This one just clears the value, but can we remove defined variable completely? – Eugen Konkov Aug 09 '23 at 22:17