]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
2 years agoRun scripts on the host by default 1701/head
Daan De Meyer [Wed, 26 Jul 2023 14:33:57 +0000 (16:33 +0200)] 
Run scripts on the host by default

Scripts currently run chrooted in the image. This is not great because
it means the tool you want to run from a script has to be installed in
the image, even if it has --root support to run from outside the image.

Specifically, to install extra packages from a script, you currently
have to install the package manager inside the image itself. Even then,
it might be completely different than the package manager on the host
(both in version and in build options), possibly leading to all kinds
of weird issues.

To allow users to install extra packages from scripts, we now default
to running scripts on the host. Additionally, to make life easy for
users, we provide a set of scripts in the PATH for the package managers
we support that call them with the necessary options to install packages
in the same way mkosi installs packages into the root directory. This
means all that users have to do is "dnf install xxx" from the script to
install a new package into the root directory.

Because some tools do not have a --root option and to provide an easy
migration for users that depend on scripts running in the image, we
also put a script "mkosi-chroot" in the PATH which uses bubblewrap to chroot
into the image as we did before. Users can keep their old scripts working
by simply adding the following to the top of their script:

```
if [ "$container" != "mkosi" ]; then
    exec mkosi-chroot $SCRIPT "$@"
fi
```

When running scripts on the host, no APIVFS directories are mounted into
the image. When using the "mkosi-chroot" and package manager scripts, the APIVFS
directories are automatically mounted before executing the corresponding
command. The apivfs_cmd() function is introduced to make implementing this
easier.

Additionally, we now always consider the current working directory a
BuildSources= directory. BuildSources= is now used to declare additional
source directories. The current working directory can always be overmounted
with another directory by simply specifying a source directory in BuildSources=
without a target directory.

To allow scripts running on the host to find the image, we set the
BUILDROOT variable for all scripts.

To prevent scripts on the host from messing with the host system when mkosi
is running as root, we extend the sandboxing to cover many more directories
which are all mounted read-only while a script is executing.

This change also allows scripts to be written in python or other scripting
languages without having to install python into the image itself.

2 years agoSort packages for every distribution
Daan De Meyer [Thu, 3 Aug 2023 11:28:12 +0000 (13:28 +0200)] 
Sort packages for every distribution

2 years agoFix rename bug in finalize_staging()
Daan De Meyer [Thu, 3 Aug 2023 08:20:32 +0000 (10:20 +0200)] 
Fix rename bug in finalize_staging()

2 years agoMerge pull request #1725 from DaanDeMeyer/stdin
Daan De Meyer [Wed, 2 Aug 2023 13:20:04 +0000 (15:20 +0200)] 
Merge pull request #1725 from DaanDeMeyer/stdin

Give scripts access to sys.stdin

2 years agocentos: Fix extras source repo id 1725/head
Daan De Meyer [Wed, 2 Aug 2023 13:04:19 +0000 (15:04 +0200)] 
centos: Fix extras source repo id

2 years agoGive scripts access to sys.stdin
Daan De Meyer [Wed, 2 Aug 2023 12:54:51 +0000 (14:54 +0200)] 
Give scripts access to sys.stdin

It's very useful to be able to put "bash" in a script to get a shell,
so let's support that.

2 years agoMake sure outputs are always prefixed with the output name
Daan De Meyer [Wed, 2 Aug 2023 11:20:38 +0000 (13:20 +0200)] 
Make sure outputs are always prefixed with the output name

Our output unlinking logic currently works based off the name of
the output. Everything that is prefixed with the output name is
removed. We need to fix that properly, but for now, let's make sure
that all outputs that we generate are prefixed with the name of the
output.

2 years agoMerge pull request #1723 from DaanDeMeyer/stuff
Daan De Meyer [Wed, 2 Aug 2023 11:15:16 +0000 (13:15 +0200)] 
Merge pull request #1723 from DaanDeMeyer/stuff

Stuff

2 years agoMove run_build_script() next to the other script functions 1723/head
Daan De Meyer [Wed, 2 Aug 2023 08:42:32 +0000 (10:42 +0200)] 
Move run_build_script() next to the other script functions

2 years agoUse explicit "build" verb when calling ukify
Daan De Meyer [Wed, 2 Aug 2023 08:34:22 +0000 (10:34 +0200)] 
Use explicit "build" verb when calling ukify

2 years agoIntroduce StrEnum and Use enum.auto() everywhere
Daan De Meyer [Wed, 2 Aug 2023 08:32:58 +0000 (10:32 +0200)] 
Introduce StrEnum and Use enum.auto() everywhere

2 years agorun: Fix escaping bug
Daan De Meyer [Tue, 1 Aug 2023 06:29:16 +0000 (08:29 +0200)] 
run: Fix escaping bug

2 years agoinstaller: Return list[PathString] instead of list[str]
Daan De Meyer [Mon, 31 Jul 2023 19:55:50 +0000 (21:55 +0200)] 
installer: Return list[PathString] instead of list[str]

2 years agoMerge pull request #1722 from DaanDeMeyer/fix
Daan De Meyer [Tue, 1 Aug 2023 21:12:28 +0000 (23:12 +0200)] 
Merge pull request #1722 from DaanDeMeyer/fix

More comprehensive tmpfile fix

2 years agoMore comprehensive tmpfile fix 1722/head
Daan De Meyer [Tue, 1 Aug 2023 20:30:05 +0000 (22:30 +0200)] 
More comprehensive tmpfile fix

2 years agoMerge pull request #1721 from DaanDeMeyer/fixes
Daan De Meyer [Tue, 1 Aug 2023 19:24:39 +0000 (21:24 +0200)] 
Merge pull request #1721 from DaanDeMeyer/fixes

Fixes

2 years agoOnly do a lazy umount when needed 1721/head
Daan De Meyer [Tue, 1 Aug 2023 16:45:37 +0000 (18:45 +0200)] 
Only do a lazy umount when needed

2 years agoMake sure the temporary directory is recalculated when we modify TMPDIR
Daan De Meyer [Tue, 1 Aug 2023 16:44:49 +0000 (18:44 +0200)] 
Make sure the temporary directory is recalculated when we modify TMPDIR

2 years agoMerge pull request #1719 from DaanDeMeyer/distro
Daan De Meyer [Mon, 31 Jul 2023 13:27:25 +0000 (15:27 +0200)] 
Merge pull request #1719 from DaanDeMeyer/distro

Distribution cleanups

2 years agoRework clean_package_manager_metadata() 1719/head
Daan De Meyer [Wed, 26 Jul 2023 21:14:23 +0000 (23:14 +0200)] 
Rework clean_package_manager_metadata()

2 years agoRework distributions
Daan De Meyer [Fri, 28 Jul 2023 10:10:19 +0000 (12:10 +0200)] 
Rework distributions

Let's make the following changes
- Instead of having an instance of the installer object stored in
  MkosiState, let's have an installer() method on the Distribution
  enum that returns the specific type implementing the distribution
- Let's move Distribution to mkosi.distributions
- Let's add a method to DistributionInstaller to return the package
  type instead of storing it directly in the Distribution enum
- Let's add methods to the Distribution enum that delegate to its
  installer type
- Use enum.auto() instead of specifying values directly.

2 years agoqemu: Remove debian specific workaround
Daan De Meyer [Mon, 31 Jul 2023 12:53:19 +0000 (14:53 +0200)] 
qemu: Remove debian specific workaround

This seems to not be required anymore so let's drop the workaround

2 years agoMerge pull request #1718 from DaanDeMeyer/builddep
Daan De Meyer [Mon, 31 Jul 2023 12:19:48 +0000 (14:19 +0200)] 
Merge pull request #1718 from DaanDeMeyer/builddep

Add source and debuginfo repositories

2 years agocentos: Add debuginfo and source repositories 1718/head
Daan De Meyer [Thu, 27 Jul 2023 12:53:49 +0000 (14:53 +0200)] 
centos: Add debuginfo and source repositories

2 years agodebian/ubuntu: Add source and debug repositories
Daan De Meyer [Thu, 27 Jul 2023 10:58:38 +0000 (12:58 +0200)] 
debian/ubuntu: Add source and debug repositories

These are not trivial to integrate into --repositories so we enable
them by default.

2 years agofedora: Add source and debuginfo repositories
Daan De Meyer [Wed, 26 Jul 2023 15:48:11 +0000 (17:48 +0200)] 
fedora: Add source and debuginfo repositories

2 years agodnf: Enable builddep plugin
Daan De Meyer [Wed, 26 Jul 2023 15:47:35 +0000 (17:47 +0200)] 
dnf: Enable builddep plugin

This one is actually useful and has to be invoked explicitly so
there's no harm in enabling it.

2 years agoapt: Make invoke_apt() and apt_cmd() slightly more generic
Daan De Meyer [Fri, 28 Jul 2023 09:31:58 +0000 (11:31 +0200)] 
apt: Make invoke_apt() and apt_cmd() slightly more generic

Let's allow passing in the apt command we want to execute.

2 years agoFix filelists on fedora
Daan De Meyer [Wed, 26 Jul 2023 14:12:58 +0000 (16:12 +0200)] 
Fix filelists on fedora

We should only download these on older Fedora's, not newer ones.

2 years agoSet KERNEL_INSTALL_BYPASS=1 in load_environment()
Daan De Meyer [Wed, 26 Jul 2023 13:54:14 +0000 (15:54 +0200)] 
Set KERNEL_INSTALL_BYPASS=1 in load_environment()

2 years agoMerge pull request #1714 from DaanDeMeyer/installer
Daan De Meyer [Mon, 31 Jul 2023 09:25:08 +0000 (11:25 +0200)] 
Merge pull request #1714 from DaanDeMeyer/installer

Move package manager logic to separate submodule

2 years agoSeparate out functions to get package manager commands + options 1714/head
Daan De Meyer [Fri, 28 Jul 2023 09:22:02 +0000 (11:22 +0200)] 
Separate out functions to get package manager commands + options

2 years agoIntroduce zypper.py for zypper related logic
Daan De Meyer [Fri, 28 Jul 2023 09:19:45 +0000 (11:19 +0200)] 
Introduce zypper.py for zypper related logic

2 years agoIntroduce apt.py for apt related logic
Daan De Meyer [Wed, 26 Jul 2023 13:17:21 +0000 (15:17 +0200)] 
Introduce apt.py for apt related logic

2 years agoIntroduce pacman.py for pacman related logic
Daan De Meyer [Wed, 26 Jul 2023 13:13:28 +0000 (15:13 +0200)] 
Introduce pacman.py for pacman related logic

2 years agoIntroduce dnf.py for dnf related logic
Daan De Meyer [Wed, 26 Jul 2023 13:09:42 +0000 (15:09 +0200)] 
Introduce dnf.py for dnf related logic

We put this in a new "installer" submodule as well.

2 years agodocs: fix syntax
Zbigniew Jędrzejewski-Szmek [Sat, 29 Jul 2023 10:44:37 +0000 (12:44 +0200)] 
docs: fix syntax

Quick fixup for a7944939724bcf1fab8cb9129d5ad9e47d0ddf99.

2 years agoIntroduce rmtree() and remove unlink_try_hard()
Daan De Meyer [Wed, 26 Jul 2023 13:06:40 +0000 (15:06 +0200)] 
Introduce rmtree() and remove unlink_try_hard()

2 years agoMove sandboxing from chroot_cmd() to bwrap()
Daan De Meyer [Fri, 28 Jul 2023 17:07:51 +0000 (19:07 +0200)] 
Move sandboxing from chroot_cmd() to bwrap()

Let's leave it to bwrap() to set up any sandboxing that we need.
Let's also add a bit more sandboxing to bwrap(), to avoid details
from the host accidentally leaking into the image builds.

2 years agorun: Make env dict[str, str]
Daan De Meyer [Fri, 28 Jul 2023 09:07:54 +0000 (11:07 +0200)] 
run: Make env dict[str, str]

2 years agoUpdate documentation
Daan De Meyer [Thu, 27 Jul 2023 17:05:05 +0000 (19:05 +0200)] 
Update documentation

Too many changes to mention. Primarily this commit updates or removes
outdated documentation.

2 years agoMerge pull request #1708 from DaanDeMeyer/fixes
Daan De Meyer [Fri, 28 Jul 2023 16:39:47 +0000 (18:39 +0200)] 
Merge pull request #1708 from DaanDeMeyer/fixes

Fixes

2 years agoarch: Put testing repositories first if enabled so they take priority 1708/head
Daan De Meyer [Fri, 28 Jul 2023 13:52:43 +0000 (15:52 +0200)] 
arch: Put testing repositories first if enabled so they take priority

2 years agorun: Unshare pid namespace again in bwrap()
Daan De Meyer [Fri, 28 Jul 2023 13:51:48 +0000 (15:51 +0200)] 
run: Unshare pid namespace again in bwrap()

This was removed when we had a brief experiment with running everything
with bwrap(), but since we don't do that anymore, let's add this back
to make chroot detection work again.

2 years agorun: Make sure we resolve relative /etc/resolv.conf symlinks properly
Daan De Meyer [Fri, 28 Jul 2023 10:54:26 +0000 (12:54 +0200)] 
run: Make sure we resolve relative /etc/resolv.conf symlinks properly

If the symlink is relative, we should resolve it relative to /etc/resolv.conf
and not /

2 years agoOnly install bash in the initrd on gentoo
Daan De Meyer [Fri, 28 Jul 2023 08:39:48 +0000 (10:39 +0200)] 
Only install bash in the initrd on gentoo

I initially added this because no shell is pulled into the initrd
by default on gentoo when just installing systemd and util-linux.
Since this seems to override other distro's default shell, let's
limit this to just gentoo and rely on other distros pulling in a
shell via dependencies.

2 years agoMerge pull request #1700 from DaanDeMeyer/stuff
Daan De Meyer [Wed, 26 Jul 2023 07:56:18 +0000 (09:56 +0200)] 
Merge pull request #1700 from DaanDeMeyer/stuff

Stuff

2 years agoAlways install bash in the initrd 1700/head
Daan De Meyer [Sun, 23 Jul 2023 08:01:25 +0000 (10:01 +0200)] 
Always install bash in the initrd

Let's make sure we always have a shell in the initrd so that sulogin
works correctly.

2 years agoMake sure all dnf log files are removed
Daan De Meyer [Sat, 22 Jul 2023 18:22:18 +0000 (20:22 +0200)] 
Make sure all dnf log files are removed

2 years agoUse input instead of writing to stdin in make_cpio()
Daan De Meyer [Sat, 22 Jul 2023 18:20:48 +0000 (20:20 +0200)] 
Use input instead of writing to stdin in make_cpio()

Also remove the text= argument from spawn() and default it to True
just like run().

2 years agoGentoo fixes
Daan De Meyer [Sun, 23 Jul 2023 17:33:34 +0000 (19:33 +0200)] 
Gentoo fixes

- Drop --update, we never want to update packages, only install new
ones
- Drop --changed-use and --new-use, these apply to updating an existing
system, we're always installing a new one
- Drop --deep and --complete-graph-if-new-use, these don't seem to
have any noticeable effect
- Move getbinpkg from FEATURE to emerge CLI option --getbinpkg
- Do not disable spinner and candy option
- Explicitly disable all sandboxing features

2 years agoMerge pull request #1692 from DaanDeMeyer/stuff
Daan De Meyer [Sat, 22 Jul 2023 18:19:02 +0000 (20:19 +0200)] 
Merge pull request #1692 from DaanDeMeyer/stuff

More stuff

2 years agoAdd move_tree() 1692/head
Daan De Meyer [Fri, 21 Jul 2023 19:13:05 +0000 (21:13 +0200)] 
Add move_tree()

This function is intended to be a more efficient way of moving trees
than shutil.move(). Specifically, it will use reflinks and btrfs
snapshots if possible to make copying more efficient.

2 years agoRename btrfs.py to tree.py and move copy_path() into it
Daan De Meyer [Fri, 21 Jul 2023 19:15:30 +0000 (21:15 +0200)] 
Rename btrfs.py to tree.py and move copy_path() into it

Let's hide btrfs subvolumes as an implementation detail in a new
tree module. We have two functions, make_tree() and copy_tree()
(renamed from copy_path()), which will both take advantage of btrfs
subvolumes if configured to do so.

We also extend copy_tree() to not try to snapshot files.

2 years agomount_passwd() cleanups
Daan De Meyer [Fri, 21 Jul 2023 18:32:47 +0000 (20:32 +0200)] 
mount_passwd() cleanups

2 years agoMake MkosiState a context manager
Daan De Meyer [Fri, 21 Jul 2023 14:59:00 +0000 (16:59 +0200)] 
Make MkosiState a context manager

We have to make sure we properly cleanup the workspace object we
allocate so let's make MkosiState a context manager so we do just
that.

2 years agoMove more enums to config.py
Daan De Meyer [Fri, 21 Jul 2023 13:11:21 +0000 (15:11 +0200)] 
Move more enums to config.py

Also move is_xxx_distribution() functions into Distribution enum.

2 years agoSet TMPDIR=state.workspace when building an image
Daan De Meyer [Fri, 21 Jul 2023 13:04:19 +0000 (15:04 +0200)] 
Set TMPDIR=state.workspace when building an image

2 years agogentoo: Set FEATURES by appending to /etc/portage/make.conf
Daan De Meyer [Sat, 22 Jul 2023 14:53:43 +0000 (16:53 +0200)] 
gentoo: Set FEATURES by appending to /etc/portage/make.conf

Setting via the environment variable doesn't work in all cases, so
let's append to /etc/portage/make.conf instead. This allows us to
get rid of the custom devtpms for portage as it doesn't try to chown
tty's anymore now that userpriv is actually disabled.

2 years agoDrop filesystem_options() and make xfs default for centos again
Daan De Meyer [Fri, 21 Jul 2023 12:37:50 +0000 (14:37 +0200)] 
Drop filesystem_options() and make xfs default for centos again

Requires https://github.com/systemd/systemd/pull/26541 but after that
building XFS root filesystems will work reliably again and we can use
xfs as the default filesystem for centos which removes the need for
filesystem_options().

2 years agoGet rid of kernel_image() in DistributionInstaller
Daan De Meyer [Fri, 21 Jul 2023 10:51:10 +0000 (12:51 +0200)] 
Get rid of kernel_image() in DistributionInstaller

Instead, let's make sure in the install_packages() method that we
can find the kernel image at the expected location.

2 years agoGet rid of kernel_command_line() in DistributionInstaller
Daan De Meyer [Fri, 21 Jul 2023 10:22:21 +0000 (12:22 +0200)] 
Get rid of kernel_command_line() in DistributionInstaller

Let's just let anyone using CentOS 8 Stream set rw themselves.

2 years agoFix do-a-release script
Daan De Meyer [Fri, 21 Jul 2023 10:19:42 +0000 (12:19 +0200)] 
Fix do-a-release script

2 years agoMove Verb to config.py
Daan De Meyer [Fri, 21 Jul 2023 10:19:32 +0000 (12:19 +0200)] 
Move Verb to config.py

2 years agoMerge pull request #1667 from DaanDeMeyer/gentoo-bwrap
Daan De Meyer [Sat, 22 Jul 2023 10:21:15 +0000 (12:21 +0200)] 
Merge pull request #1667 from DaanDeMeyer/gentoo-bwrap

gentoo: Use bwrap() instead of run_workspace_command() to run emerge

2 years agogentoo: Use bwrap() instead of run_workspace_command() to run emerge 1667/head
Daan De Meyer [Thu, 6 Jul 2023 11:34:59 +0000 (13:34 +0200)] 
gentoo: Use bwrap() instead of run_workspace_command() to run emerge

Similar to the other distros, run the package manager with bwrap()
instead of run_workspace_command(). Also disable the sandboxing of
emerge as we do it in mkosi already.

2 years agogentoo: Drop --keep-going
Daan De Meyer [Thu, 6 Jul 2023 11:38:48 +0000 (13:38 +0200)] 
gentoo: Drop --keep-going

If we fail to emerge a package, we want to fail the emerge process
instead of trying to continue.

2 years agoMerge pull request #1691 from DaanDeMeyer/distribution
Daan De Meyer [Fri, 21 Jul 2023 09:55:11 +0000 (11:55 +0200)] 
Merge pull request #1691 from DaanDeMeyer/distribution

Distribution stuff

2 years agocentos: Remove distribution specific checks 1691/head
Daan De Meyer [Fri, 21 Jul 2023 09:16:51 +0000 (11:16 +0200)] 
centos: Remove distribution specific checks

This also reworks the mirror specification for centos and related
distros to duplicate less code. gpgurls of the Repo() struct is also
made into a tuple instead of a list.

2 years agoSimplify become_root()
Daan De Meyer [Thu, 20 Jul 2023 14:27:40 +0000 (16:27 +0200)] 
Simplify become_root()

- Instead of forking, use spawn() to start the newuidmap, newgidmap
processes early
- Instead of multiprocessing.Event(), use flock to handle the necessary
locking

2 years agofedora: Remove distribution specific checks
Daan De Meyer [Fri, 21 Jul 2023 07:33:30 +0000 (09:33 +0200)] 
fedora: Remove distribution specific checks

This also drops support for specifying rawhide-f37, etc.

2 years agoKernel modules fixlets
Daan De Meyer [Thu, 20 Jul 2023 13:36:12 +0000 (15:36 +0200)] 
Kernel modules fixlets

- Add some more information on what we're doing
- Move running modinfo and calculating dependencies out of the files()
generator so that the "Making cpio" step doesn't include running modinfo
and calculating the dependencies.

2 years agoMerge pull request #1686 from DaanDeMeyer/env
Daan De Meyer [Thu, 20 Jul 2023 11:34:30 +0000 (13:34 +0200)] 
Merge pull request #1686 from DaanDeMeyer/env

Stop tmpfiles from creating subvolumes

2 years agoRework selinux labelling 1686/head
Daan De Meyer [Thu, 20 Jul 2023 10:39:54 +0000 (12:39 +0200)] 
Rework selinux labelling

Let's run setfiles on the host instead of inside the image. To make
this work, we have to explicitly tell it to use the binary policy
from the image to check contexts against.

2 years agoOnly execute preset, hwdb, sysusers tools if they are available
Daan De Meyer [Thu, 20 Jul 2023 09:34:39 +0000 (11:34 +0200)] 
Only execute preset, hwdb, sysusers tools if they are available

Let's reduce the number of dependencies needed to create a tools tree
by only executing these tools if they are installed on the system.

2 years agoStop tmpfiles from creating subvolumes
Daan De Meyer [Thu, 20 Jul 2023 08:55:41 +0000 (10:55 +0200)] 
Stop tmpfiles from creating subvolumes

Generally when building an image there's no point in creating nested
subvolumes in these directories so let's disable that.

2 years agoMove default environment into MkosiConfig
Daan De Meyer [Thu, 20 Jul 2023 08:45:41 +0000 (10:45 +0200)] 
Move default environment into MkosiConfig

We already do this for --kernel-command-line-extra and --credential,
let's be consistent and do --environment the same way.

2 years agoMerge pull request #1682 from DaanDeMeyer/rework-tools
Daan De Meyer [Thu, 20 Jul 2023 07:38:49 +0000 (09:38 +0200)] 
Merge pull request #1682 from DaanDeMeyer/rework-tools

Rework user/mount namespace handling and tools tree

2 years agogentoo: stop passing USE environment to emerge
Paymon MARANDI [Wed, 19 Jul 2023 16:03:58 +0000 (12:03 -0400)] 
gentoo: stop passing USE environment to emerge

also make sure we stay with systemd-9999 (version built from git) in
order keep up with changes in systemd

Signed-off-by: Paymon MARANDI <darwinskernel@gmail.com>
2 years agoRework user/mount namespace handling and tools tree 1682/head
Daan De Meyer [Mon, 17 Jul 2023 21:21:38 +0000 (23:21 +0200)] 
Rework user/mount namespace handling and tools tree

The biggest change is that instead of making bwrap() responsible
for mounting the tools tree, we do it ourselves before we build/boot
each image. We do the same for remounting the top level directories
read-only, instead of leaving it to bwrap(), we do it once at the
start of run_verb(). Because we now mess with the host system mounts
ourselves again, we also go back to unconditionally unsharing a mount
namespace, even when running as root.

With the above out of the way, there's no real reason left to run
regular executables with bwrap(), so those are moved back to be
executed using run(). The above changes also remove the need for
bwrap_cmd(), so it is merged back with bwrap() again.

One nasty caveat of overmounting /usr ourselves at the start of
execution is that some python modules are loaded dynamically and we
need to make sure this has happened before we start overmounting /usr.

Finally, this commit also gets rid of running the image build in a
subprocess. Instead, after doing the build and doing the final tools
tree mount for the image we're going to boot/qemu/ssh into, if we're
going to do an unprivleged operation, we change uid/gid to the invoking
user. This is more or less the same as running these operations unprivileged
outside of the user namespace.

For boot/shell, these only run privileged, so we check beforehand
that we're running as root, and this doesn't change after become_root(),
so since we're just root all the time, there's no need to run the image
build in a subprocess.

To keep ssh working, we have to trick it into recognizing our user in
the user namespace by overmounting /etc/passwd with a file containing
an entry for the mapped user uid.

We also unify more of the uid/gid handling in run_verb() in general.

2 years agoAllow overriding the python interpreter used by mkosi
Daan De Meyer [Tue, 18 Jul 2023 09:15:12 +0000 (11:15 +0200)] 
Allow overriding the python interpreter used by mkosi

e.g. on CentOS 8 python3 is python 3.6. python 3.9 can be installed,
but it'll be installed as python3.9, so we need a way to override the
interpreter used by mkosi.

2 years agoRevert "Rename various "root" arguments to "tools""
Daan De Meyer [Mon, 17 Jul 2023 16:06:33 +0000 (18:06 +0200)] 
Revert "Rename various "root" arguments to "tools""

This reverts commit 41ef3c05e1d1caec39c9917b2776aee4f0c29599.

2 years agoRevert "Make tools= argument for bwrap() required"
Daan De Meyer [Mon, 17 Jul 2023 16:04:31 +0000 (18:04 +0200)] 
Revert "Make tools= argument for bwrap() required"

This reverts commit 2bd37a648bcace0ae505328a51eed78c9cb923b4.

2 years agoRevert "Add our own "which" implementation"
Daan De Meyer [Mon, 17 Jul 2023 16:04:12 +0000 (18:04 +0200)] 
Revert "Add our own "which" implementation"

This reverts commit d0d2044316548123eaa9fca3745d29a653107edd.

2 years agoMake tools= argument for bwrap() required
Daan De Meyer [Mon, 17 Jul 2023 14:57:14 +0000 (16:57 +0200)] 
Make tools= argument for bwrap() required

We generally always want this to be used, so let's make it required.
Also, add tools= to the one invocation of bwrap() that wasn't
forwarding it yet.

2 years agoMerge pull request #1677 from DaanDeMeyer/cache
Jörg Behrmann [Mon, 17 Jul 2023 14:24:38 +0000 (16:24 +0200)] 
Merge pull request #1677 from DaanDeMeyer/cache

Rework chrooting and add scripts support to bwrap()

2 years agoMake sure util-linux is installed in the initrd
Daan De Meyer [Mon, 17 Jul 2023 11:30:01 +0000 (13:30 +0200)] 
Make sure util-linux is installed in the initrd

systemd on Fedora prefers to install util-linux-core instead of
util-linux which doesn't ship sulogin which makes starting
emergency.service enter an infinite loop. Let's make sure util-linux
is installed so sulogin is available in the initrd.

2 years agoAdd our own "which" implementation 1677/head
Daan De Meyer [Mon, 17 Jul 2023 07:50:28 +0000 (09:50 +0200)] 
Add our own "which" implementation

shutil.which() doesn't take into account any configured tools tree
so let's implement our own which() that does take the tools tree into
account.

2 years agoRename extra argument of invoke_apt() to packages
Daan De Meyer [Sun, 16 Jul 2023 21:46:13 +0000 (23:46 +0200)] 
Rename extra argument of invoke_apt() to packages

2 years agoAdd scripts support to bwrap() and use it for chrooting
Daan De Meyer [Sun, 16 Jul 2023 20:24:38 +0000 (22:24 +0200)] 
Add scripts support to bwrap() and use it for chrooting

The new scripts argument to bwrap() allows providing a mapping of
script names to command lines. Each of these becomes a script in a
directory that's prepended to PATH before executing the command
given to bwrap(). This allows us to make extra commands available
to scripts we execute with bwrap().

The first usage of this is to replace the extra argument which is
used to provide the extra arguments to chroot into the root directory.
Instead, we provide a chroot script and use that in the command line
we pass to bwrap() to perform the chroot.

2 years agoDrop checks for binaries in config loading
Daan De Meyer [Sun, 16 Jul 2023 19:25:00 +0000 (21:25 +0200)] 
Drop checks for binaries in config loading

These might be in the tools tree so let's not check whether they
exist early.

2 years agoStop prepending extra search paths during config validation
Daan De Meyer [Sun, 16 Jul 2023 18:24:12 +0000 (20:24 +0200)] 
Stop prepending extra search paths during config validation

Not required anymore now that we have version comparisons in pure
python.

2 years agoRemove kwargs argument from run() and spawn()
Daan De Meyer [Sun, 16 Jul 2023 17:57:54 +0000 (19:57 +0200)] 
Remove kwargs argument from run() and spawn()

Let's prefer listing arguments explicitly so that mypy can catch
the wrong ones easily.

2 years agoImplement run_workspace_command() on top of bwrap()
Daan De Meyer [Sun, 16 Jul 2023 16:09:01 +0000 (18:09 +0200)] 
Implement run_workspace_command() on top of bwrap()

Instead of duplicating the apivfs setup between bwrap() and
run_workspace_command(), let's make bwrap() responsible for setting
up the apivfs and implement chrooting on top of it. Specifically,
to chroot, we just run bwrap nested to do the chroot and any
additional setup before running the actual command. This is implemented
in the new chroot_cmd() function which returns the command to do the
chroot. This also sets the stage for running scripts on the host and
somehow providing the chroot_cmd() command to scripts to use themselves
to run something inside the root directory.

To keep --debug-shell working smoothly for scripts, we pass the chroot
command as a new extra argument to bwrap() so we can also apply it when
starting the debug shell.

We also rework the /etc/resolv.conf bind mounting so we don't have
to do any cleanup after the command finishes.

2 years agoReplace kwargs from bwrap with individual arguments
Daan De Meyer [Sun, 16 Jul 2023 16:01:43 +0000 (18:01 +0200)] 
Replace kwargs from bwrap with individual arguments

kwargs makes it impossible for mypy to point out wrong arguments
so let's drop it in favor of individual arguments to get more out
of the type checker.

2 years agoRename various "root" arguments to "tools"
Daan De Meyer [Sun, 16 Jul 2023 15:56:25 +0000 (17:56 +0200)] 
Rename various "root" arguments to "tools"

"tools" is more descriptive than "root" about indicating that we're
passing a tree of tools.

2 years agoPut dnf command last again in the cmdline
Daan De Meyer [Sun, 16 Jul 2023 09:59:19 +0000 (11:59 +0200)] 
Put dnf command last again in the cmdline

It only has to be in front of the cmd specific options, which in
our case was only --allowerasing, so since that's gone now, let's
put the command last again.

2 years agoDrop --allowerasing dnf option
Daan De Meyer [Sun, 16 Jul 2023 09:51:55 +0000 (11:51 +0200)] 
Drop --allowerasing dnf option

We don't want to allow dnf to remove packages when installing other
packages. If it wants to do so that indicates something is wrong
elsewhere.

2 years agoFix logdir handling for dnf
Daan De Meyer [Fri, 14 Jul 2023 13:00:46 +0000 (15:00 +0200)] 
Fix logdir handling for dnf

logdir= is always taken relative to the installroot. Let's leave it
at it's default value and remove any log files from the install root
after running dnf.

2 years agoMerge pull request #1675 from DaanDeMeyer/loglevel
Daan De Meyer [Thu, 13 Jul 2023 16:25:45 +0000 (18:25 +0200)] 
Merge pull request #1675 from DaanDeMeyer/loglevel

Beef up --kernel-command-line-extra= defaults a little bit