mkosi
mkosi copied to clipboard
`--environment` cannot pass environment variable value with a space
mkosi commit the issue has been seen with
main
Used host distribution
Arch Linux
Used target distribution
Arch Linux
Linux kernel version used
No response
CPU architectures issue was seen on
x86_64
Unexpected behaviour you saw
Trying to pass an environment variable with spaces causes the splits it up making it impossible to pass something like "-O ^orphan_file".
This is not an issue with --env-file FYI, Haven't tested Enviroment as a Config option.
mkosi --debug -d arch -p systemd --seed 0e9a6fe0-68f6-408c-bbeb-136054d20445 --source-date-epoch 1662046009 -m https://archive.archlinux.org/repos/2024/06/30/ --force -o bar --environment=SYSTEMD_REPART_MKFS_OPTIONS_EXT4="-O ^orphan_file" --environment=SYSTEMD_LOG_LEVEL=debug
Debug print of the passed env variable to systemd-repart
ENV {'SYSTEMD_TMPFILES_FORCE_SUBVOL': '0', 'TERM': 'screen-256color', 'SOURCE_DATE_EPOCH': '1662046009', 'GIT_PROXY_SSL_CAINFO': '/proxy.cacert', 'SYSTEMD_REPART_MKFS_OPTIONS_EXT4': '-O', '^orphan_file': '', 'SYSTEMD_LOG_LEVEL': 'debug'}
‣ + systemd-repart --empty=allow --size=auto --dry-run=no --json=pretty --no-pager --offline=yes --seed 0e9a6fe0-68f6-408c-bbeb-136054d20445 /home/jelle/.cache/mkosi/mkosi-workspace-ko3gkhyb/staging/bar.raw --root=/buildroot --empty=create --defer-partitions esp,xbootldr --generate-fstab=/etc/fstab --generate-crypttab=/etc/crypttab --definiti
Successfully populated ext4 filesystem.
Executing mkfs command: mkfs.ext4 -L root-x86-64 -U 1dde1f49-50c2-4e9f-ac6a-93112acd4880 -I 256 -m 0 -E discard,lazy_itable_init=1 -b 4096 -T default /var/tmp/.#repartbe039c3943c2d910 -d /var/tmp/.#repart58e854ebe43787fa -O
Successfully forked off '(mkfs)' as PID 95812.
PR_SET_MM_ARG_START failed: Operation not permitted
mkfs.ext4: option requires an argument -- 'O'
Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-C cluster-size]
[-i bytes-per-inode] [-I inode-size] [-J journal-options]
[-G flex-group-size] [-N number-of-inodes] [-d root-directory|tarball]
[-m reserved-blocks-percentage] [-o creator-os]
[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
[-t fs-type] [-T usage-type ] [-U UUID] [-e errors_behavior][-z undo_file]
[-jnqvDFSV] device [blocks-count]
Used mkosi config
No response
mkosi output
No response
It's definitely not working as one would expect, but
python -m mkosi -E 'FOO=foo\ bar' -E BAR='qux quz' summary
shows the two different versions, with the former working and the latter not. FOO will have value foo bar and BAR will have value qux, with another broken environment variable quz as in your example.
The parser for the environment variables works as expected, but the problem is getting the right thing through from the shell.
The Environment= setting worked for me, when I quickly tested it by adding a line to the test.
As far as I can it's due to the delimiter being a space in
ConfigSetting(
dest="environment",
short="-E",
metavar="NAME[=VALUE]",
section="Content",
parse=config_make_dict_parser(delimiter=" ", parse=parse_environment, unescape=True),
match=config_match_key_value,
help="Set an environment variable when running scripts",
),
So this seems to implicate that you can pass multiple env vars via one --environment invocation which is not something I would expect. That is proven by:
python -m mkosi -E 'FOO=1 BAR=1' summary
FOO=1
BAR=1
So mkosi --environment=SYSTEMD_REPART_MKFS_OPTIONS_EXT4="\"-O ^orphan_file\"" does the trick. I don't think we can change this at this point without breaking compat so I'll close this with the mention of the workaround.