Create /usr/lib/systemd/system/mac-keyboard.service with the following contents:
[Unit]
Description=mac-keyboard
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo 2 > /sys/module/hid_apple/parameters/fnmode"
ExecStop=/bin/sh -c "echo 1 > /sys/module/hid_apple/parameters/fnmode"
RemainAfterExit=yes