]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
2 years agoEnsure output is compatible with systemd-sysupdate 1386/head
Michael A Cassaniti [Mon, 1 May 2023 04:36:16 +0000 (14:36 +1000)] 
Ensure output is compatible with systemd-sysupdate

When using `systemd-sysupdate` it is wise to use split artifacts and to
compress artifacts. These changes ensure that split artifacts are compressed
and the file paths are stored in the checksum.

Please note that `systemd-sysupdate` expects a checksum name of `SHA256SUMS`
and uses the contained file names to determine which files to download. The
compression suffix is also used to determine how to decompress files.

Additional CI checks have been added to make sure no regressions in output
format occur.

2 years agoUpdate files docs
Daan De Meyer [Sat, 29 Apr 2023 13:48:46 +0000 (15:48 +0200)] 
Update files docs

2 years agodistro: debian: allow RemovePackages
Tj [Tue, 2 May 2023 07:52:28 +0000 (08:52 +0100)] 
distro: debian: allow RemovePackages

When using RemovePackages= apt may refuse to remove what it considers
essential packages even when they are effectively empty meta packages or
contain only usr/share/doc/${package}/

This causes build failure like this:
Reading state information...
Package 'netcat-openbsd' is not installed, so not removed
Package 'net-tools' is not installed, so not removed
Package 'man-db' is not installed, so not removed
Package 'groff-base' is not installed, so not removed
The following packages will be REMOVED:
  cron* dmidecode* fdisk* ifupdown* init* iproute2* iputils-ping*
  isc-dhcp-client* isc-dhcp-common* kmod* libbpf0* libbsd0* libcap2-bin*
  libdns-export1110* libedit2* libelf1* libfdisk1* libisc-export1105*
  libjansson4* libmd0* libmnl0* libnftables1* libnftnl11* libxtables12*
nano*
  netbase* nftables* udev* vim-common* vim-tiny* xxd*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  init
0 upgraded, 0 newly installed, 31 to remove and 0 not upgraded.
E: Essential packages were removed and -y was used without
--allow-remove-essential.
‣ "apt-get purge vim-tiny vim-common nano nftables netcat-openbsd
netbase net-tools isc-dhcp-common isc-dhcp-client iputils-ping iprout
e2 udev kmod fdisk dmidecode man-db init ifupdown groff-base cron"
returned non-zero exit code 100.
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,

As we do know what we are doing to have configured these removals, tell
apt to allow it.

2 years agoMerge pull request #1513 from keszybz/more-man
Daan De Meyer [Mon, 1 May 2023 11:16:54 +0000 (13:16 +0200)] 
Merge pull request #1513 from keszybz/more-man

More man page adjustments

2 years agoMerge pull request #1506 from DaanDeMeyer/profiles
Daan De Meyer [Mon, 1 May 2023 11:15:33 +0000 (13:15 +0200)] 
Merge pull request #1506 from DaanDeMeyer/profiles

Add preset support

2 years agoAdd preset support 1506/head
Daan De Meyer [Tue, 25 Apr 2023 13:04:19 +0000 (15:04 +0200)] 
Add preset support

Presets can be defined in mkosi.presets/. A preset is just like a
regular config file/directory, except that mkosi can build multiple
presets sequentially.

If mkosi.presets/ exists, for each preset mkosi will read the global
configuration, followed by the individual preset configuration. It
will then build each of the presets in alpha-numerical order. Later
presets can use outputs of earlier presets, specifically using the
BaseTrees= and Initrds= options.

While this has many use cases, one promising use case is to allow
building an initrd and a final image that uses that initrd within a
single invocation of mkosi.

2 years agoDo prebuilt initrds by default
Daan De Meyer [Sun, 30 Apr 2023 20:41:54 +0000 (22:41 +0200)] 
Do prebuilt initrds by default

Let's stop running kernel-install in favor of always doing prebuilt
initrds by default. We reimplement the depmod hook of kernel-install
ourselves (required for centos stream 8).

If no initrd is provided by the user, we build a minimal one ourselves
that's sufficient to boot in a qemu VM. If the default initrd is not
sufficient, the upcoming preset support can be used to build a custom
initrd instead.

2 years agoAllow specifying --bootable without an argument
Daan De Meyer [Sun, 30 Apr 2023 20:39:16 +0000 (22:39 +0200)] 
Allow specifying --bootable without an argument

2 years agoDon't fail if we can't retrieve default credentials
Daan De Meyer [Mon, 1 May 2023 07:45:06 +0000 (09:45 +0200)] 
Don't fail if we can't retrieve default credentials

Let's not fail if we can't run ssh-add or timedatectl to get the
SSH key or timezone.

2 years agoAllow specifying empty --directory to not parse any config files
Daan De Meyer [Sun, 30 Apr 2023 19:15:27 +0000 (21:15 +0200)] 
Allow specifying empty --directory to not parse any config files

2 years agorepart: Support mkfs options from configured environment
Michael A Cassaniti [Mon, 1 May 2023 00:16:04 +0000 (10:16 +1000)] 
repart: Support mkfs options from configured environment

2 years agoSwitch back to using ttyS0 as the default serial console
Daan De Meyer [Sun, 30 Apr 2023 15:07:01 +0000 (17:07 +0200)] 
Switch back to using ttyS0 as the default serial console

virtio_console is not always a builtin kernel module on all the
distributions we support. This means that the kernel can only
start logging to it after the initramfs has been unpacked and the
virtio_console module has been loaded from it. Any message that's
logged to kmsg before that dissapears into the void which makes
debugging boot failures rather difficult.

Instead, until systemd-stub is recent enough in all supported distros
to receive extra kernel cmdline arguments via smbios, let's use a
default kernel cmdline of "console=ttyS0" so that the serial console
works by default but can still be overridden by users.

2 years agoAlways create /init symlink if systemd is installed
Daan De Meyer [Sun, 30 Apr 2023 14:38:36 +0000 (16:38 +0200)] 
Always create /init symlink if systemd is installed

Let's always create the /init symlink if systemd is installed so that
the kernel picks it up at /init when we try to use this output as the
initramfs.

2 years agoRefactor ACLs + make sure they apply to base trees
Daan De Meyer [Sun, 30 Apr 2023 11:24:07 +0000 (13:24 +0200)] 
Refactor ACLs + make sure they apply to base trees

Let's refactor ACLs so that they're all applied/removed in the same
function. Let's also make sure they apply to base trees as well.

2 years agoAdd gzip compression support
Daan De Meyer [Sat, 29 Apr 2023 09:26:02 +0000 (11:26 +0200)] 
Add gzip compression support

2 years agoDefault to xz fast compression
Daan De Meyer [Sat, 29 Apr 2023 09:24:56 +0000 (11:24 +0200)] 
Default to xz fast compression

Let's default to fast compression instead of better compression.

Also drop pixz support since it's superseded by xz's own multithreading
support.

2 years agoFixup rpmdb location on Debian when running zypper as well
Daan De Meyer [Fri, 28 Apr 2023 18:39:27 +0000 (20:39 +0200)] 
Fixup rpmdb location on Debian when running zypper as well

zypper uses rpmdb under the hood, just like dnf, so it suffers from
the same rpmdb problem on Debian/Ubuntu, so let's apply the same fix.

2 years agoAdd missing newline
Daan De Meyer [Fri, 28 Apr 2023 18:37:43 +0000 (20:37 +0200)] 
Add missing newline

2 years agocentos: Make sure glibc-all-langpacks doesn't get installed
Daan De Meyer [Fri, 28 Apr 2023 09:21:20 +0000 (11:21 +0200)] 
centos: Make sure glibc-all-langpacks doesn't get installed

On CentOS 8, glibc-all-langpacks is pulled in as a dependency of
filesystem. Let's make sure dnf prefers glibc-minimal-langpack by
installing it explicitly.

2 years agoFix genkey
Daan De Meyer [Fri, 28 Apr 2023 08:36:56 +0000 (10:36 +0200)] 
Fix genkey

2 years agoClean up unlinking outputs a bit
Daan De Meyer [Fri, 28 Apr 2023 08:20:08 +0000 (10:20 +0200)] 
Clean up unlinking outputs a bit

2 years agoAdd missing colon
Daan De Meyer [Fri, 28 Apr 2023 06:25:57 +0000 (08:25 +0200)] 
Add missing colon

2 years agoFix PathExists
Daan De Meyer [Thu, 27 Apr 2023 19:03:51 +0000 (21:03 +0200)] 
Fix PathExists

We now chdir() to the current config directory so we don't have to
take the current path into account anymore.

2 years agoDon't try to install build packages if we have none
Daan De Meyer [Thu, 27 Apr 2023 18:09:34 +0000 (20:09 +0200)] 
Don't try to install build packages if we have none

2 years agoCache only files installed on top of base trees
Daan De Meyer [Thu, 27 Apr 2023 13:21:03 +0000 (15:21 +0200)] 
Cache only files installed on top of base trees

Currently, when base trees are used in incremental mode, we cache
the base trees as well. When running from a cache copy, any changes
to the base trees are not taken into account. Let's change this and
only cache the files we add/change/delete on top of the base layers.
This makes sure that we can still use our cache even if the base layer
changes, since we won't ignore all changes made to the base layer.

2 years agoStore file hash and signature in output directory
Michael A Cassaniti [Wed, 26 Apr 2023 08:11:10 +0000 (18:11 +1000)] 
Store file hash and signature in output directory

2 years agoCI fixes
Daan De Meyer [Wed, 26 Apr 2023 12:53:34 +0000 (14:53 +0200)] 
CI fixes

2 years agoMerge pull request #1516 from mcassaniti/fix-signing
Daan De Meyer [Wed, 26 Apr 2023 08:47:49 +0000 (10:47 +0200)] 
Merge pull request #1516 from mcassaniti/fix-signing

Fix signing of checksums, especially for non-root user

2 years agohash signing: Use keyring of running user for non-root builds 1516/head
Michael A Cassaniti [Wed, 26 Apr 2023 04:32:12 +0000 (14:32 +1000)] 
hash signing: Use keyring of running user for non-root builds

`gpg` will attempt to use the root user keyring When running as a non-root
user instead of using the keyring of the user that is executing `mkosi`.
This change will attempt to use the keyring given by `GNUPGHOME` and
fallback to using `~/.gnupg`.

2 years agobase-trees: Fix typo in path
Michael A Cassaniti [Wed, 26 Apr 2023 04:41:48 +0000 (14:41 +1000)] 
base-trees: Fix typo in path

2 years agoEnsure that username and uid are consistent
Joerg Behrmann [Tue, 25 Apr 2023 16:53:57 +0000 (18:53 +0200)] 
Ensure that username and uid are consistent

While SUDO_UID and SUDO_GID are useful, since sudo allows to run things as
different UID and GID, SUDO_USER is less useful, since it can't change the
mapping from UID to name in the namespace it's in. Let's cut out the middleman
of getpass.getuser, that looks through several more environment
variables (LOGNAME, USER, LNAME, USERNAME) before falling back to os.getuid and
looking up the corresponding name and do that right away.

2 years agohash signing: Fix using default key
Michael A Cassaniti [Wed, 26 Apr 2023 04:27:04 +0000 (14:27 +1000)] 
hash signing: Fix using default key

The default key needs to be specified before the file to sign

2 years agoman: add more info about qemu monitor 1513/head
Zbigniew Jędrzejewski-Szmek [Tue, 25 Apr 2023 16:55:41 +0000 (18:55 +0200)] 
man: add more info about qemu monitor

This is very hard to discover, but useful. Let's give the
users a hint.

2 years agoman: drop explicit Fedora version from example
Zbigniew Jędrzejewski-Szmek [Tue, 25 Apr 2023 16:52:17 +0000 (18:52 +0200)] 
man: drop explicit Fedora version from example

We don't really care which version is used exactly, but 24 is almost
certainly not the right one. By not specifying the version we let mkosi
pick something suitable.

2 years agoman: use '$' to signify unprivileged commands, '#' for privileged
Zbigniew Jędrzejewski-Szmek [Tue, 25 Apr 2023 16:51:02 +0000 (18:51 +0200)] 
man: use '$' to signify unprivileged commands, '#' for privileged

It's always nicer to do things not as root.

Also adjust some phrasing and minor details in a few places.

2 years agoman: drop line about authors
Zbigniew Jędrzejewski-Szmek [Tue, 25 Apr 2023 16:23:18 +0000 (18:23 +0200)] 
man: drop line about authors

This header is rendered in the github preview in a fairly ugly way.
Nevertheless, we can't get rid of the whole thing because then pandoc generates
a man page without a header. But let's at least drop the info about authors and
date to make the whole thing less prominent.

2 years agoMerge pull request #1509 from DaanDeMeyer/profiles-prep
Jörg Behrmann [Tue, 25 Apr 2023 16:01:57 +0000 (18:01 +0200)] 
Merge pull request #1509 from DaanDeMeyer/profiles-prep

Profiles preparation

2 years agoUnbreak Invokinguser
Joerg Behrmann [Tue, 25 Apr 2023 15:10:34 +0000 (17:10 +0200)] 
Unbreak Invokinguser

2 years agochdir() without going back in parse() 1509/head
Daan De Meyer [Tue, 25 Apr 2023 12:58:35 +0000 (14:58 +0200)] 
chdir() without going back in parse()

We never need to leave the directory specified with --directory, so
let's not leave it.

2 years agoMake sure path to parse_config() is correct after chdir()
Daan De Meyer [Tue, 25 Apr 2023 12:57:00 +0000 (14:57 +0200)] 
Make sure path to parse_config() is correct after chdir()

2 years agoMove cache, build and install directories to [Output] section.
Daan De Meyer [Tue, 25 Apr 2023 11:53:37 +0000 (13:53 +0200)] 
Move cache, build and install directories to [Output] section.

2 years agoRemove distro specific output directory
Daan De Meyer [Tue, 25 Apr 2023 11:41:42 +0000 (13:41 +0200)] 
Remove distro specific output directory

Let's move the cache images to mkosi.cache/ and go back to non
distro specific output directories. This gives us a stable path
for the build outputs that doesn't depend on the specific distro or
version used.

2 years agoRestore old PATH when prepend_to_environ_path finishes
Daan De Meyer [Tue, 25 Apr 2023 10:42:17 +0000 (12:42 +0200)] 
Restore old PATH when prepend_to_environ_path finishes

2 years agoMake bump and genkey CLI image independent verbs
Daan De Meyer [Tue, 25 Apr 2023 10:19:30 +0000 (12:19 +0200)] 
Make bump and genkey CLI image independent verbs

In preparation for adding multiple images support, let's make these
commands work only with command line arguments.

2 years agoSplit MkosiArgs from MkosiConfig
Daan De Meyer [Tue, 25 Apr 2023 09:21:50 +0000 (11:21 +0200)] 
Split MkosiArgs from MkosiConfig

Let's put the arguments that are not associated with an image into
a separate dataclass.

2 years agoReturn MkosiConfig from MkosiConfigParser.parse()
Daan De Meyer [Tue, 25 Apr 2023 09:03:50 +0000 (11:03 +0200)] 
Return MkosiConfig from MkosiConfigParser.parse()

2 years agoRemove support for passing arguments to the build script.
Daan De Meyer [Tue, 25 Apr 2023 09:14:09 +0000 (11:14 +0200)] 
Remove support for passing arguments to the build script.

This doesn't end up working well in practice, so let's drop support
for this.

2 years agoUse default_factory for selecting default mirror
Daan De Meyer [Mon, 24 Apr 2023 20:57:57 +0000 (22:57 +0200)] 
Use default_factory for selecting default mirror

2 years agoMerge pull request #1508 from behrmann/evenmorematch
Jörg Behrmann [Tue, 25 Apr 2023 14:05:27 +0000 (16:05 +0200)] 
Merge pull request #1508 from behrmann/evenmorematch

Allow globs if image ID matches and implement not equal for image version matches

2 years agoMerge pull request #1500 from behrmann/followupsv1
Daan De Meyer [Tue, 25 Apr 2023 13:35:55 +0000 (15:35 +0200)] 
Merge pull request #1500 from behrmann/followupsv1

Assorted followups

2 years agodoc: add a table which match supports what 1508/head
Joerg Behrmann [Tue, 25 Apr 2023 13:21:09 +0000 (15:21 +0200)] 
doc: add a table which match supports what

2 years agoconfig: allow globs when matching image IDs
Joerg Behrmann [Tue, 25 Apr 2023 12:39:56 +0000 (14:39 +0200)] 
config: allow globs when matching image IDs

2 years agoci: drop unneeded build dependency
Joerg Behrmann [Tue, 25 Apr 2023 12:21:08 +0000 (14:21 +0200)] 
ci: drop unneeded build dependency

2 years agoconfig: add missing version comparision for non-equality
Joerg Behrmann [Tue, 25 Apr 2023 12:20:40 +0000 (14:20 +0200)] 
config: add missing version comparision for non-equality

2 years agoImplement __bool__ and __str__ for compression enum 1500/head
Joerg Behrmann [Mon, 24 Apr 2023 12:44:01 +0000 (14:44 +0200)] 
Implement __bool__ and __str__ for compression enum

2 years agoMake keyword arguments of config_make_list_parser keyword-only
Joerg Behrmann [Mon, 24 Apr 2023 10:42:21 +0000 (12:42 +0200)] 
Make keyword arguments of config_make_list_parser keyword-only

2 years agoconfig: default to True for required in path parsing functions
Joerg Behrmann [Mon, 24 Apr 2023 10:57:46 +0000 (12:57 +0200)] 
config: default to True for required in path parsing functions

2 years agoAdd back bootable to summary output
Joerg Behrmann [Mon, 24 Apr 2023 10:41:33 +0000 (12:41 +0200)] 
Add back bootable to summary output

2 years agoMake InvokingUser just a namespace for functions
Joerg Behrmann [Fri, 21 Apr 2023 20:54:26 +0000 (22:54 +0200)] 
Make InvokingUser just a namespace for functions

The sequence of calls to the underlying functions remains the same, but it's
shorter and there are no intermediate dataclass instance constructed.

2 years agoMerge pull request #1504 from behrmann/morematch
Daan De Meyer [Tue, 25 Apr 2023 11:39:57 +0000 (13:39 +0200)] 
Merge pull request #1504 from behrmann/morematch

Add matching on image ID and version

2 years agoci: build current systemd-analyze for unit tests 1504/head
Joerg Behrmann [Tue, 25 Apr 2023 08:04:49 +0000 (10:04 +0200)] 
ci: build current systemd-analyze for unit tests

2 years agoaction: add back version output of the binaries we build
Joerg Behrmann [Tue, 25 Apr 2023 06:52:37 +0000 (08:52 +0200)] 
action: add back version output of the binaries we build

2 years agoEnable --repo-dir for Debian and Ubuntu
Georges Discry [Sun, 23 Apr 2023 10:27:01 +0000 (12:27 +0200)] 
Enable --repo-dir for Debian and Ubuntu

Additional repositories can now be configured for Debian and Ubuntu.

Because APT can only be configured with a single path for
`Dir::Etc::sourceparts`, the content of the directories listed in
`repo_dirs` are copied in a `apt/sources.list.d` directory managed by
mkosi outside the image root. Therefore, only one file will be kept if
several files have the same name.

Like the main `sources.list` generated by mkosi, the additional
repositories are copied in the image if APT is installed.

2 years agoconfig: add ImageVersion matching
Joerg Behrmann [Mon, 24 Apr 2023 18:20:25 +0000 (20:20 +0200)] 
config: add ImageVersion matching

2 years agoconfig: Improve GenericVersion performance
Joerg Behrmann [Mon, 24 Apr 2023 18:19:59 +0000 (20:19 +0200)] 
config: Improve GenericVersion performance

2 years agoconfig: Add Match on ImageId
Joerg Behrmann [Mon, 24 Apr 2023 15:41:43 +0000 (17:41 +0200)] 
config: Add Match on ImageId

2 years agoMerge pull request #1491 from DaanDeMeyer/exception
Daan De Meyer [Mon, 24 Apr 2023 20:00:16 +0000 (22:00 +0200)] 
Merge pull request #1491 from DaanDeMeyer/exception

Tweak exception handling

2 years agoTweak exception handling 1491/head
Daan De Meyer [Sun, 23 Apr 2023 13:47:38 +0000 (15:47 +0200)] 
Tweak exception handling

- Remove optional exception argument of die() in favor of just using
  logging.error() and re-raising the exception
- Instead of raising RuntimeError in die(), just call sys.exit()
  instead which raises SystemExit.
- Show stacktrace of every exception that isn't SystemExit,
  KeyboardInterrupt or subprocess.CalledProcessError.

2 years agoDrop safe_tar_extract()
Daan De Meyer [Sun, 23 Apr 2023 13:46:26 +0000 (15:46 +0200)] 
Drop safe_tar_extract()

Let's just run tar as a child process instead.

2 years agoFix FileExistsError exception
Daan De Meyer [Mon, 24 Apr 2023 16:23:30 +0000 (18:23 +0200)] 
Fix FileExistsError exception

2 years agoMerge pull request #1501 from DaanDeMeyer/fixes
Daan De Meyer [Mon, 24 Apr 2023 15:53:49 +0000 (17:53 +0200)] 
Merge pull request #1501 from DaanDeMeyer/fixes

Various fixes

2 years agotests: Add tests for Match sections
Joerg Behrmann [Mon, 24 Apr 2023 15:34:18 +0000 (17:34 +0200)] 
tests: Add tests for Match sections

2 years agoRemove unnecessary newline in log_step() 1501/head
Daan De Meyer [Mon, 24 Apr 2023 13:18:18 +0000 (15:18 +0200)] 
Remove unnecessary newline in log_step()

2 years agoRevert back to shell based chmod solution for bwrap
Daan De Meyer [Mon, 24 Apr 2023 13:11:11 +0000 (15:11 +0200)] 
Revert back to shell based chmod solution for bwrap

Mounting the host directories doesn't work because those directories
are owned by root on the host which translates to nobody in the user
namespace, breaking systemd tmpfiles tests.

2 years agoUse conditional apivfs with Debian/Ubuntu and Arch as well
Daan De Meyer [Mon, 24 Apr 2023 14:28:59 +0000 (16:28 +0200)] 
Use conditional apivfs with Debian/Ubuntu and Arch as well

Arch's filesystem package ships apivfs directories as well and
in Debian/Ubuntu, we don't want to have apivfs mounted when running
the apt update and when only downloading packages.

2 years agoUse stderr to check for tty in foreground()
Daan De Meyer [Mon, 24 Apr 2023 13:10:07 +0000 (15:10 +0200)] 
Use stderr to check for tty in foreground()

stdin/stdout might be redirected for other purposes, let's use stderr
instead to detect if we're connected to a terminal.

2 years agoDrop var_tmp() from MkosiState
Daan De Meyer [Mon, 24 Apr 2023 13:09:48 +0000 (15:09 +0200)] 
Drop var_tmp() from MkosiState

2 years agoMake --debug a boolean and add --debug-shell
Daan De Meyer [Mon, 24 Apr 2023 11:38:51 +0000 (13:38 +0200)] 
Make --debug a boolean and add --debug-shell

Let's drop the support for multiple string arguments since we only
have "run" anyway and make --boolean a simple yes/no option. To
get an interactive shell on failure, a new option --debug-shell is
added.

2 years agoSupport matching against any of a list of releases
Georges Discry [Mon, 24 Apr 2023 11:02:45 +0000 (13:02 +0200)] 
Support matching against any of a list of releases

2 years agoMerge pull request #1495 from DaanDeMeyer/stuff
Daan De Meyer [Mon, 24 Apr 2023 11:00:40 +0000 (13:00 +0200)] 
Merge pull request #1495 from DaanDeMeyer/stuff

Various refactorings and improvements

2 years agoRemove for_cache from MkosiState and centralize cached in build_image() 1495/head
Daan De Meyer [Sat, 22 Apr 2023 17:28:48 +0000 (19:28 +0200)] 
Remove for_cache from MkosiState and centralize cached in build_image()

Instead of passing these two booleans to every function, let's centralize
their usage in build_image().

2 years agoRemove --cache-initrd
Daan De Meyer [Sat, 22 Apr 2023 17:16:37 +0000 (19:16 +0200)] 
Remove --cache-initrd

2 years agoUse uid, gid directly instead of state.uid, state.gid
Daan De Meyer [Sat, 22 Apr 2023 17:12:42 +0000 (19:12 +0200)] 
Use uid, gid directly instead of state.uid, state.gid

2 years agoMove MkosiConfig and load_args() and config.py
Daan De Meyer [Fri, 21 Apr 2023 20:38:55 +0000 (22:38 +0200)] 
Move MkosiConfig and load_args() and config.py

And all the other related changes to make that work.

2 years agoMove MkosiState to state.py
Daan De Meyer [Fri, 21 Apr 2023 20:25:40 +0000 (22:25 +0200)] 
Move MkosiState to state.py

2 years agoRework bwrap run functions
Daan De Meyer [Fri, 21 Apr 2023 20:19:47 +0000 (22:19 +0200)] 
Rework bwrap run functions

- To split up our dependencies more, we need to make run.py
  independent of MkosiState, so let's do that.
- To get rid of the shell hacks in both functions to chmod /tmp,
  /var/tmp and /dev/shm, let's just mount the relevant files from
  the host which have the right permissions.
- Fixing the above exposed a bug in the logic to set up rpm based
  systems, which all ship a filesystem package that includes
  directories such as /tmp, /proc, /sys, ... which we overmount
  with apivfs or tmpfs filesystems when running rpm, causing errors
  when the filesystem package tries to set up these directories. To
  ensure these directories are created with the permissions from the
  filesystem package, the run_with_apivfs() function is renamed to
  bwrap() and gains an apivfs argument, which takes a path to set
  up apivfs directories in. If not provided, no apivfs is set up.
  This is then used to install the filesystem package without apivfs
  so that the directories can be created with the right permissions.
- The various rpm distributions now install the filesystem package
  instead of the setup package by default, so we can disable apivfs
  properly while filesystem is being installed. system-user-root
  was removed for opensuse because the filesystem package depends on
  it.

2 years agoFix rpmdb symlinks
Daan De Meyer [Mon, 24 Apr 2023 10:42:48 +0000 (12:42 +0200)] 
Fix rpmdb symlinks

On CentOS, we were creating the wrong symlink. Let's use a proper
relative symlink that always works regardless of whether we're chrooted
or not.

On Debian/Ubuntu, we weren't creating a symlink at all. So let's make
sure we also create a symlink there and use a relative symlink there as
well.

We use os.path.relpath() because Path().relative_to() can only do relative
paths to subpaths which isn't the case here. In the future we can set
strict=False and use relative_to().

2 years agoRename backend.py to util.py
Daan De Meyer [Fri, 21 Apr 2023 19:47:07 +0000 (21:47 +0200)] 
Rename backend.py to util.py

backend.py is a horrible name, let's use util.py instead.

2 years agoUse an entry point instead of a script
Georges Discry [Thu, 20 Apr 2023 20:10:06 +0000 (22:10 +0200)] 
Use an entry point instead of a script

The use of a custom script to launch mkosi has several shortcomings:

1. It translates `$PKEXEC_UID` into various `$SUDO_`* variables. That
   translation is lost if mkosi is run as a zipapp or as a module with
   `pkexec python3 -m mkosi`.
2. It has to muck around with `$PYTHONPATH` to launch mkosi directly
   from its source code.
3. It is tied to setuptools and has no equivalent in the standard
   project metadata (as in pyproject.toml).
4. And it also has to find the correct interpreter and maybe muck around
   with `$PYTHONPATH` to launch mkosi from its installation, which may
   be on the system, in the user's sitedir or in a virtualenv, as a
   standard or an editable installation.

Point 1 is not needed anymore now that `mkosi.backend.current_user()` is
used everywhere.

Point 2 can be done by directly running mkosi as a module from its
sources with:

- `[sudo|pkexec] python3 -m mkosi` inside the project directory
- `[sudo] PYTHONPATH=<PROJECT_PATH> python3 -m mkosi` from anywhere
- `[sudo|pkexec] <PROJECT_PATH>/bin/mkosi` from anywhere. The script is
  now a simple shim that is only used for this use case and not
  installed anymore.

Point 3 and 4 are better supported by using a `"console_scripts"` entry
point when installed. However, it is not possible anymore to run a
user-installed mkosi with sudo/pkexec.

2 years agoAdd missing complete_step() when installing build packages
Daan De Meyer [Mon, 24 Apr 2023 07:55:26 +0000 (09:55 +0200)] 
Add missing complete_step() when installing build packages

2 years agofix duplicate entry in github action
Malte Poll [Mon, 24 Apr 2023 07:52:19 +0000 (09:52 +0200)] 
fix duplicate entry in github action

2 years agoUse `getpass.getuser()` to get the name of the current user
Georges Discry [Sun, 23 Apr 2023 20:35:38 +0000 (22:35 +0200)] 
Use `getpass.getuser()` to get the name of the current user

`os.getlogin()` can fail and has no fallback, whereas
`getpass.getuser()` takes the environment variables into account and
falls back on `pwd`.

2 years agoDisallow `<SOURCE>:<TARGET>` with an empty target
Georges Discry [Sun, 23 Apr 2023 12:51:08 +0000 (14:51 +0200)] 
Disallow `<SOURCE>:<TARGET>` with an empty target

The configurations of the form `<SOURCE>[:<TARGET>]` require an absolute
target if given. However, `<SOURCE>:` would be ambiguously interpreted
as `<SOURCE>` so it is now disallowed.

For reference, `systemd-nspawn --bind` uses a similar form and refuses
to take an empty target.

2 years agoAllow setting empty environment variables
Georges Discry [Sun, 23 Apr 2023 12:47:44 +0000 (14:47 +0200)] 
Allow setting empty environment variables

Trying to set an empty environment variable with `FOO=` would instead
pass the `FOO` variable from the host, which is the expected behavior
when `=` is missing.

2 years agodebian: Add TODO to drop /var/lib/dpkg/status logic when possible
Daan De Meyer [Sat, 22 Apr 2023 20:41:33 +0000 (22:41 +0200)] 
debian: Add TODO to drop /var/lib/dpkg/status logic when possible

It's created automatically by apt since apt 2.5.4 so add a note that
we can drop it once that version is widely available. Also disable
dpkg locking since it causes a apt failure due to not being able to
access the lock file in /var/lib/dpkg. Since we're building in a
chroot, we don't care about locking anyway.

2 years agoUse python logging module for logging
Daan De Meyer [Fri, 21 Apr 2023 19:18:14 +0000 (21:18 +0200)] 
Use python logging module for logging

Let's get rid of our home grown solution and use python's logging
module instead.

2 years agoSupport matching against any of a list of distributions
Daan De Meyer [Sun, 23 Apr 2023 12:35:55 +0000 (14:35 +0200)] 
Support matching against any of a list of distributions

2 years agoDisplay "Skeleton Trees" in the summary again
Georges Discry [Sat, 22 Apr 2023 10:13:30 +0000 (12:13 +0200)] 
Display "Skeleton Trees" in the summary again

The skeleton trees were lost from the summary with e1bbc39.

2 years agoFix installation of essential packages on Debian stretch
Georges Discry [Fri, 21 Apr 2023 23:24:24 +0000 (01:24 +0200)] 
Fix installation of essential packages on Debian stretch

There is a bug in Debian stretch where `libuuid1` (which is essential)
unnecessarily depends on `passwd`. When configuring the essential
packages and their dependencies, `passwd` is configured before
`base-passwd` and the installation fails.

debootstrap did not have this issue because it explicitly orders the
installation of some essential packages, including `base-passwd`.

By explicitly installing `base-passwd` first, the rest of the essential
packages can then be configured without failure.

2 years agoUse shlex escaping in Environment
Georges Discry [Fri, 21 Apr 2023 19:56:10 +0000 (21:56 +0200)] 
Use shlex escaping in Environment

The Environment configuration takes lists of space-separated values and
combine them in a single list, splitting the values on spaces and
newlines. However, environment variables might sometimes need a space in
their value, which is currently impossible to configure.

Instead of blindly splitting the values on spaces and newlines, they are
now split with shlex. Spaces, newlines and backslashes can be escaped
with backslashes, single quotes and double quotes.

This behavior also more closely matches the Environment directive of systemd.