Daan De Meyer [Wed, 3 Jan 2024 13:46:16 +0000 (14:46 +0100)]
Only mount cache overlay if base trees are specified and Overlay= is not enabled
The setup() method of some distributions creates files in the root
directory which means that checking if the root directory is empty
doesn't work. Instead, let's check if any base trees were specified
explicitly.
Daan De Meyer [Wed, 3 Jan 2024 13:44:09 +0000 (14:44 +0100)]
Cache skeleton trees
These are only intended for files that affect package manager
operation so we should be able to cache this step without any issues
since if the skeleton tree is changed, users are likely going to want
to throw away their cache regardless.
Daan De Meyer [Tue, 2 Jan 2024 16:11:12 +0000 (17:11 +0100)]
Unshare fewer namespaces
These were primarily unshared to get the systemd unit test suite passing.
Now that the systemd test suite passes even if these are not unshared,
let's stop unsharing them as they don't make much sense for the operations
were doing and nspawn doesn't run when some of these are unshared.
Daan De Meyer [Mon, 1 Jan 2024 16:49:08 +0000 (17:49 +0100)]
Rename various symbols
- Let's get rid of the Mkosi prefix everywhere. Python has namespaced
modules for a reason, let's make use of that.
- Let's also rename State to Context, to match systemd where Context
is generally used as well instead of State.
Daan De Meyer [Tue, 2 Jan 2024 20:55:05 +0000 (21:55 +0100)]
Preserve target directories stat when copying extra/skeleton trees
When copying extra and skeleton trees, let's not touch the permissions
of directories that already exist in the image's root directory. 99%
of the time, the directories are only in the extra tree to make sure
the files go in the right directory in the image's root directory and
serve no other purpose so it makes sense to ignore their metadata in
this case.
Because cp does not support this natively (either all permissions are
copied for directories and files or none are copied), we implement this
ourselves by saving the necessary permissions before we call cp and
restoring them afterwards).
In (at least) Debian, some binaries such as awk point to
/etc/alternatives which would not exist and cause apt-key to fail
without specifying the exact keyring (e.g. when using /etc/apt/trusted.gpg.d)
Disable debsig for dpkg by default as they do in debian.
From the default dpkg.conf:
# Do not enable debsig-verify by default; since the distribution is not using
# embedded signatures, debsig-verify would reject all packages.
no-debsig
Daan De Meyer [Fri, 22 Dec 2023 14:29:06 +0000 (15:29 +0100)]
Mount entire /etc from package manager tree into sandbox
Instead of mounting individual directories, let's just mount the
entire /etc into the sandbox. This allows any tool we run through
the sandbox to pick up configuration from the package manager tree
without having to add explicit support for it in mkosi.
This also removes our special casing for uki.conf. ukify will now
pick up its configuration from its canonical location just like all
the other tools.
Daan De Meyer [Fri, 22 Dec 2023 11:18:40 +0000 (12:18 +0100)]
Mount package manager trees
Now that /etc and /var are free game when running within bwrap()
because we don't mount in the directories from the host anymore,
let's take advantage of that by mounting all our package manager
configuration to the canonical location in /etc instead of configuring
the package managers via their CLI or config file to look in the
right directory.
This also makes us look for rpm configuration in /etc/rpm instead
of /usr/lib/rpm as that's now possible.
Malte Poll [Fri, 22 Dec 2023 11:41:10 +0000 (12:41 +0100)]
bubblewrap: try to mount /nix/store readonly
Similar to most usrmerged systems, NixOS stores all installed
binaries and libraries in /nix/store.
To make mkosi work on NixOS, the nix store should be mounted by default.
Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
Daan De Meyer [Thu, 21 Dec 2023 15:00:44 +0000 (16:00 +0100)]
Run more binaries with bwrap()
Let's sandbox more of the image build. This isolates more of the
build from the host which reduces the chance of leaking in host
specific details into the image.
Daan De Meyer [Wed, 20 Dec 2023 20:31:56 +0000 (21:31 +0100)]
Sandbox more in bwrap()
Let's not make the full root filesystem available to commands
running in bwrap(). Instead, limit it to some select directories.
- /usr
- Various directories from /etc. Note that this also means we can
get rid of mount_tools() as all these directories are now mounted
in bwrap() instead. This also allows us to get rid of the overlay
hack in mount_tools() to create the necessary mount points. The
goal is to get rid of as many of these as possible over time.
- /var/tmp
- /tmp
Because to make this work we have to pass MkosiConfig into bwrap(),
we split off a new file bubblewrap.py with all the bubblewrap stuff.
To avoid having to import MkosiState and bwrap() into tree.py,
install_tree() is moved __init__.py
Daan De Meyer [Thu, 21 Dec 2023 10:07:36 +0000 (11:07 +0100)]
Run depmod and modinfo on host again
Running these in the chroot is much slower when building images for
another architecture. Also, we might soon have a way to prevent dnf
from running depmod (see
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2743), so
let's adopt that when it is merged.
Michael Ferrari [Wed, 20 Dec 2023 01:12:07 +0000 (02:12 +0100)]
`Output=` now has the version appended if unset
Previously `Output=` would only default to `ImageId=` if unset, but the
output files would have the version appended, resulting in `%o` not
returning the actual name of the output files.
This also moves the default handling to a `default_factory`
Michael Ferrari [Wed, 20 Dec 2023 01:10:53 +0000 (02:10 +0100)]
Output files starting with `Output=` are removed
As preparation for the removal of `config.output_with_version` the
removal of output files now only factors in `config.output` as prefix
and no longer removes based on version suffix, due to that being added
to `config.output` in a following commit.
Daan De Meyer [Tue, 19 Dec 2023 15:29:02 +0000 (16:29 +0100)]
Stop bind mounting /sys in chroot environments
The only reason we do this is to make systemd's unit test suite
pass. https://github.com/systemd/systemd/pull/30527 fixes systemd's
test suite to not fail when /sys is not mounted, so let's drop this
bit.
Daan De Meyer [Sat, 16 Dec 2023 19:31:01 +0000 (20:31 +0100)]
ci: Drop rocky, alma and rhel-ubi
The next commit is going to add a second dimension to the test
matrix which will dramatically introduce the number of CI jobs.
Let's keep things manageable by dropping rhel-ubi, alma and rocky
which should be covered by the centos job already.
Daan De Meyer [Mon, 18 Dec 2023 13:32:31 +0000 (14:32 +0100)]
mkosi-initrd: Drop explicit CompressOutput=yes
This allows the compression passed by mkosi or the default compression
to be used instead. Note that the default is to compress the initrd, so
this doesn't change anything.
Daan De Meyer [Sat, 16 Dec 2023 23:01:56 +0000 (00:01 +0100)]
opensuse: Use curl to fetch repomd.xml
urllib.request.urlopen() means we're responsible for catching all
the exceptions and showing a proper error message to the user.
Instead, let's just shell out to curl to fetch the file which can
translate any errors into user friendly error messages for us.
Daan De Meyer [Sat, 16 Dec 2023 21:58:21 +0000 (22:58 +0100)]
Split out rpm.py and hook up rpm logic with zypper as well
We have a bunch of rpm related logic that's required when using
dnf and zypper so let's split out rpm.py and hook up everything in
both dnf and zypper.
Daan De Meyer [Sat, 16 Dec 2023 21:35:53 +0000 (22:35 +0100)]
Mount over various other directories as well if needed
On Opensuse the openssl certificates are stored in
/var/lib/ca-certificates so let's make sure we mount this directory
from the tools tree into the host as well.
The pacman keyring is stored in /etc/pacman.d/gnupg so we mount over
/etc/pacman.d as well if needed.
Daan De Meyer [Fri, 15 Dec 2023 09:55:23 +0000 (10:55 +0100)]
Use mkosi.key/mkosi.crt for SSH authentication
Instead of using the user's SSH certificate and key, let's use the
X509 certificate and private key generated by 'mkosi genkey' instead.
This saves us from having to rely on ssh-agent to get the public key
or doing otherwise complicated logic to try and find the public and
private key. We also avoid always needing a separate public/private
key just for SSH by automatically converting the X509 certificate to
a SSH public key.