]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
2 years agoactions: bump checkout to v3 to remove spuriours node.js version warnings 1281/head
Joerg Behrmann [Fri, 13 Jan 2023 12:26:46 +0000 (13:26 +0100)] 
actions: bump checkout to v3 to remove spuriours node.js version warnings

2 years agogentoo: fix unsupported escape sequence in regex
Joerg Behrmann [Fri, 13 Jan 2023 09:07:31 +0000 (10:07 +0100)] 
gentoo: fix unsupported escape sequence in regex

2 years agoUpdate typing to use generics for standard container classes
Joerg Behrmann [Fri, 13 Jan 2023 09:20:45 +0000 (10:20 +0100)] 
Update typing to use generics for standard container classes

Also use the non-deprecated typing imports

2 years agoRemove casts that are no longer necessary with Python 3.9
Joerg Behrmann [Fri, 13 Jan 2023 09:07:07 +0000 (10:07 +0100)] 
Remove casts that are no longer necessary with Python 3.9

2 years agoUpdate pathlib call sites to use Python 3.9 features
Joerg Behrmann [Tue, 29 Nov 2022 13:17:59 +0000 (14:17 +0100)] 
Update pathlib call sites to use Python 3.9 features

These are:
- the unlink method gained the parameter missing_ok=
- Path objects now have a readlink method

2 years agoUse the walrus operator were applicable
Joerg Behrmann [Fri, 13 Jan 2023 09:01:25 +0000 (10:01 +0100)] 
Use the walrus operator were applicable

2 years agoUse removeprefix and removesuffix were applicable
Joerg Behrmann [Tue, 29 Nov 2022 12:54:18 +0000 (13:54 +0100)] 
Use removeprefix and removesuffix were applicable

2 years agoDrop subprocess workaround for pre python 3.9
Joerg Behrmann [Thu, 1 Sep 2022 14:41:10 +0000 (16:41 +0200)] 
Drop subprocess workaround for pre python 3.9

2 years agoBump python version in config files
Joerg Behrmann [Thu, 1 Sep 2022 14:40:41 +0000 (16:40 +0200)] 
Bump python version in config files

2 years agoMerge pull request #1304 from DaanDeMeyer/fix-rpmdb
Jörg Behrmann [Thu, 12 Jan 2023 15:04:11 +0000 (16:04 +0100)] 
Merge pull request #1304 from DaanDeMeyer/fix-rpmdb

Fix rpmdb

2 years agofedora: Remove keys for EOL releases 1304/head
Daan De Meyer [Thu, 12 Jan 2023 13:48:21 +0000 (14:48 +0100)] 
fedora: Remove keys for EOL releases

2 years agocentos: Fix rpmdb location
Daan De Meyer [Thu, 12 Jan 2023 13:47:06 +0000 (14:47 +0100)] 
centos: Fix rpmdb location

The previous logic was not working correctly. Let's simplify the
logic by only executing it for centos and only working in one
direction, if the rpmdb is written to /usr/lib/sysimage/rpm, let's
move it back to /var/lib/rpm on CentOS.

2 years ago[gentoo] merge usrmerge
Paymon MARANDI [Mon, 5 Sep 2022 21:39:04 +0000 (17:39 -0400)] 
[gentoo] merge usrmerge

upstream finally has merged-usr profiles/stage3s [1].
this makes `no-multilib/systemd/merged-usr`, and related stage3, default
for us.

[1] https://bugs.gentoo.org/843818#c2

Signed-off-by: Paymon MARANDI <darwinskernel@gmail.com>
2 years agocentos: Stop installing systemd-boot on CentOS Stream 9
Daan De Meyer [Tue, 10 Jan 2023 14:58:03 +0000 (15:58 +0100)] 
centos: Stop installing systemd-boot on CentOS Stream 9

With CentOS Stream 9 moving to systemd v252, systemd-boot has been
added back to the systemd-udev package, so we don't need to install
it from EPEL anymore.

2 years agoRemove --qemu-boot option
Daan De Meyer [Tue, 10 Jan 2023 14:33:45 +0000 (15:33 +0100)] 
Remove --qemu-boot option

Given that we're standardizing more and more on UEFI and unified
kernel images, let's drop support for qemu direct linux boot, to
drop yet another seldomly exercised codepath.

2 years agoRemove annotations import from __future__
Joerg Behrmann [Wed, 11 Jan 2023 09:32:33 +0000 (10:32 +0100)] 
Remove annotations import from __future__

PEP 563 is a PEP that stringifies type annotations. The feature was made
available as opt in. It is still very much in flux or under consideration
upstream and has fallen so much out of favour that the Python steering council
added the note [1]

    PEP 563 Postponed Evaluation of Annotations (the from __future__ import
    annotations future statement) that was originally planned for release in
    Python 3.10 has been put on hold indefinitely. See this message from the
    Steering Council for more information.

in the release notes of CPython 3.11 after punting on accepting the PEP for two
releases. The import does a lot more, but we only use the type
stringification. There is little gain from using this, but with one of the main
features of the import indefinitely on hold, it seems prudent not to use it.

With Python 3.11 the PEP 673 Self type was introduced [2], that will solve this
problem for us, once we move on to 3.11.

[1] https://docs.python.org/3.11/whatsnew/3.11.html#pep-563-may-not-be-the-future
[2] https://docs.python.org/3.11/whatsnew/3.11.html#whatsnew311-pep673

2 years agoAdd __init__.py to resources/repart
Daan De Meyer [Tue, 10 Jan 2023 11:49:43 +0000 (12:49 +0100)] 
Add __init__.py to resources/repart

This makes sure the repart/ directory in resources is included as
well.

2 years agoAdd --credential option to set systemd credentials
Daan De Meyer [Mon, 9 Jan 2023 15:40:56 +0000 (16:40 +0100)] 
Add --credential option to set systemd credentials

2 years agoidmap: fix kernel version comparison
Quentin Deslandes [Thu, 5 Jan 2023 17:39:31 +0000 (18:39 +0100)] 
idmap: fix kernel version comparison

packaging.version.parse() would create a Version object for "5.12" and a
LegacyVersion object for versions like "6.0.8-200.fc36.x86_64". This
leads to failed comparison (such as "6.0.8-200.fc36.x86_64 >= 5.12").

Use `systemd-analyze compare-versions` instead, which produce the
expected behaviour. This brings mkosi more in line with systemd
ecosystem when it comes to version strings parsing.

2 years agoMigrate to ukify
Daan De Meyer [Wed, 21 Dec 2022 15:04:02 +0000 (16:04 +0100)] 
Migrate to ukify

Let's start using ukify to generate unified kernel images instead
of implementing the logic ourselves. This also fixes issues with
overlapping PE sections.

2 years agofix invalid cross-device link
Benedict Schlueter [Fri, 23 Dec 2022 15:41:50 +0000 (16:41 +0100)] 
fix invalid cross-device link

when the workspace directory is on another filesystem (i.e. /tmp) mkosi
fails.
replace os.rename with shutil.move when we may cross filesystem
boundaries. Furthermore, chown the resulting files if the flag is set
accordingly.

2 years agofix "qemu-img convert" error
Benedict Schlueter [Fri, 23 Dec 2022 11:47:16 +0000 (12:47 +0100)] 
fix "qemu-img convert" error

the same path was used as in and output for qemu-img, this results in an
error. Use another path as output and rename the output afterward.

2 years agoMerge pull request #1276 from DaanDeMeyer/repart
Daan De Meyer [Wed, 21 Dec 2022 13:44:51 +0000 (14:44 +0100)] 
Merge pull request #1276 from DaanDeMeyer/repart

Migrate disk image building to systemd-repart

2 years agoMigrate disk image building to systemd-repart 1276/head
Daan De Meyer [Mon, 28 Nov 2022 14:45:31 +0000 (15:45 +0100)] 
Migrate disk image building to systemd-repart

Let's switch to systemd-repart to build disk images. systemd-repart
allows building disk images declaratively. repart will assemble a
disk image according to a set of partition definition files, which
it will search for in a set of predefined locations or in the locations
provided via the --definitions option. Partition definition files are
defined in the usual systemd ini style and define a single partition
each. Many aspects of the partition can be configured, including its
size, type, and how it should be populated.

Of note should be the CopyFiles= setting that allows providing a set
of files/directories from which the partition should be populated. The
CopyFiles= setting takes a list of path pairs, where the first path in
a pair defines the source location, and the second path the destination
location in the partition. If combined with repart's --root or --image
options, the source path is resolved relative to the given root directory.

Along with switching to systemd-repart, we also rework how we build
images. Previously, we first provisioned the disk image with all its
partitions, then mounted the disk image and finally populated it with
contents. Now, we provision to a regular directory on the host filesystem
first, followed by creating the disk image with systemd-repart. The partition
definition files can be supplied via the --repart-directory option or
in the mkosi.repart/ directory. If not provided, a default configuration
consisting of an automatically sized root partition and an ESP partition of
256M is used.

repart's --root switch is used so that the partition definition files
don't need to encode the full path to the root directory of the image
we're building. For example, to copy the root directory to a root
partition, it's sufficient to specify "CopyFiles=/:/" in the definition
file.

If we're building non-bootable images, any ESP partition definitions
are excluded. To allow building UKIs with an embedded roothash cmdline
parameter, we run repart twice, first to populate all partitions except
the ESP/XBOOTLDR partitions, and again to populate the ESP/XBOOTLDR
partitions including any UKIs with embedded roothash cmdline parameter
(which we determined when running repart the first time).

Because we don't know up-front anymore where the ESP partition will be
mounted, all boot loader files are installed to /boot. So to populate
an ESP partition, you'd use "CopyFiles=/boot:/" in the partition
definition file of the ESP partition.

Also, since we don't know up-front anymore which filesystem we'll be
building for, we stop installing filesystem related packages by default.
Users will be required to add the necessary filesystem packages themselves.
Similarly, we also stop installing cryptsetup and device-mapper by default
since we don't know upfront anymore whether partitions will be verity
protected or encrypted.

By switching to systemd-repart, we also set ourselves up for building
images without needing root privileges or loop devices. systemd-repart
is fully capable (from v253 onwards) of building disk images without
needing root privileges or loop devices. After we switch to
systemd-repart, we'll only need root privileges to be able to run
systemd-nspawn (which should not be necessary in the future anymore).

This PR also removes all the option related to disk image building that
can now be specified in repart definition files instead. This includes:

- Format=gpt_xxx options are replaced with a single "disk" options.
Filesystem can now be specified with repart's Format= option
- Format=plain_squashfs (Can be reproduced by a single repart squashfs
root partition combined with SplitArtifacts=yes)
- Verity= (Replaced by repart's Verity= options)
- Encrypt= (Replaced by repart's Encrypt= option)
- RootSize=, HomeSize=, VarSize=, TmpSize=, ESPSize=, SwapSize=, SrvSize=
(Replaced by repart's size options)
- UsrOnly= (replaced with `CopyFiles=/:/usr` in a usr partition definition)
- OutputSplitRoot=, OutputSplitVerity=, (Replaced by repart's SplitName= option)
- OutputSplitKernel= (UKI is now always written to its own output file)
- GPTFirstLBA (Removed, no equivalent in repart)
- ReadOnly= (Replaced by repart's ReadOnly= option per partition)
- Minimize= (Replaced by repart's Minimize= option per partition)
- CompressFs= (No equivalent in repart, can be replicated by replacing mkfs.<fs>
in $PATH with a script that adds the necessary command line option)
- MkSquashfs= (Can be replaced with a script in $PATH that invokes
the correct binary)

We also remove the WithoutUnifiedKernelImages= switch as building unified
kernel images is trivial and fast these days.

2 years agomypy: Fix version comparison
Daan De Meyer [Thu, 15 Dec 2022 14:54:34 +0000 (14:54 +0000)] 
mypy: Fix version comparison

2 years agoMake config.build_sources non-optional
Daan De Meyer [Tue, 13 Dec 2022 19:29:33 +0000 (19:29 +0000)] 
Make config.build_sources non-optional

It already was non-optional in practice, let's encode this in the
type.

2 years agoci: Rework integration tests
Daan De Meyer [Mon, 28 Nov 2022 14:42:13 +0000 (15:42 +0100)] 
ci: Rework integration tests

The current approach where we build the image as part of the integration
test is the wrong approach. Instead, we'll move to integration tests that
are integrated with a build system where building images and using them
in integration tests are separate steps. Building an image for use in an
integration test will be a regular target (custom_target()) in a build
system. Building an image that's not intended to be used in any other test
will be a regular test.

Because this model is going to be substantially different from what we have
now, let's get rid of the integration test machinery we added and temporarily
switch to the basic approach that's also used in the systemd repo for integration
tests.

2 years agoBump alma/rocky default release to "9"
Daan De Meyer [Fri, 25 Nov 2022 20:19:18 +0000 (21:19 +0100)] 
Bump alma/rocky default release to "9"

2 years agoDrop HostonlyInitrd
Daan De Meyer [Fri, 18 Nov 2022 10:07:27 +0000 (11:07 +0100)] 
Drop HostonlyInitrd

Adding this option was a mistake (mea culpa), we should limit host
impact on image builds as much as possible so let's drop this option
that makes the initrd generated by dracut host specific. This will
slow down initrd generation but once we switch to generating initrds
with mkosi we'll have a proper fix for that.

2 years agoAllow for UID mapping to be disabled
Quentin Deslandes [Wed, 16 Nov 2022 12:03:28 +0000 (13:03 +0100)] 
Allow for UID mapping to be disabled

By default, mkosi would bind mount directories with nspawn's rootidmap
option to provide consistent files ownership. If the system doesn't
support ID mapping, mkosi would fail.

Add --idmap option, default to True, to allow users to disabled UID
mapping (--idmap=no).

2 years agoRename --no-chown option to --chown
Quentin Deslandes [Wed, 16 Nov 2022 12:22:08 +0000 (13:22 +0100)] 
Rename --no-chown option to --chown

Rename --no-chown to --chown and defaults to true. This will make it
easier to reason on the code behaviour when this option is used.

2 years agoFix qemu tpm device name on aarch64
Daan De Meyer [Tue, 13 Dec 2022 12:51:48 +0000 (12:51 +0000)] 
Fix qemu tpm device name on aarch64

2 years agoidmap: also check for kernel version
Luca Boccassi [Mon, 12 Dec 2022 23:59:00 +0000 (23:59 +0000)] 
idmap: also check for kernel version

Not only nspawn 252 is required, but also kernel 5.12 for id-mapped mounts
to be available

2 years agoMerge pull request #1282 from wally-mageia/main
Daan De Meyer [Mon, 5 Dec 2022 08:12:24 +0000 (09:12 +0100)] 
Merge pull request #1282 from wally-mageia/main

Update Mageia DistributionInstaller

2 years agomageia: use release where applicable instead of state.config.release for consistency 1282/head
Jani Välimaa [Sun, 4 Dec 2022 16:35:16 +0000 (18:35 +0200)] 
mageia: use release where applicable instead of state.config.release for consistency

2 years agomageia: don't add update repo for cauldron
Jani Välimaa [Sun, 4 Dec 2022 11:00:05 +0000 (13:00 +0200)] 
mageia: don't add update repo for cauldron

2 years agomageia: add release version to repo name
Jani Välimaa [Sun, 4 Dec 2022 10:57:58 +0000 (12:57 +0200)] 
mageia: add release version to repo name

2 years agomageia: don't hardcode x86_64 arch to mirror urls
Jani Välimaa [Sun, 4 Dec 2022 10:35:09 +0000 (12:35 +0200)] 
mageia: don't hardcode x86_64 arch to mirror urls

2 years agoMerge pull request #1217 from behrmann/split4
Daan De Meyer [Tue, 29 Nov 2022 10:41:34 +0000 (11:41 +0100)] 
Merge pull request #1217 from behrmann/split4

Split v4

2 years agoRemove scaffolding for DistributionInstaller possibly being None 1217/head
Joerg Behrmann [Thu, 24 Nov 2022 16:14:40 +0000 (17:14 +0100)] 
Remove scaffolding for DistributionInstaller possibly being None

2 years agoSplit Alma and Rocky out of Centos
Joerg Behrmann [Thu, 24 Nov 2022 15:57:56 +0000 (16:57 +0100)] 
Split Alma and Rocky out of Centos

2 years agoRemove unused code
Joerg Behrmann [Thu, 24 Nov 2022 14:48:03 +0000 (15:48 +0100)] 
Remove unused code

2 years agoMove CentOS family to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 13:54:35 +0000 (14:54 +0100)] 
Move CentOS family to DistributionInstaller

2 years agoMove OpenMandriva to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 13:17:09 +0000 (14:17 +0100)] 
Move OpenMandriva to DistributionInstaller

2 years agoMove Mageia to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 12:02:56 +0000 (13:02 +0100)] 
Move Mageia to DistributionInstaller

2 years agoMove Fedora to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 11:54:34 +0000 (12:54 +0100)] 
Move Fedora to DistributionInstaller

This doubles basically all rpm/dnf functions with copies in
mkosi.distributions.fedora, but this let's us keep the split bisectable without
having to do a big refactor of what these functions look like.

2 years agoMove detect_distribution and dependents to mkosi.backend
Joerg Behrmann [Thu, 24 Nov 2022 11:52:52 +0000 (12:52 +0100)] 
Move detect_distribution and dependents to mkosi.backend

2 years agoMove unlink_try_hard and dependents into mkosi.remove
Joerg Behrmann [Thu, 24 Nov 2022 11:50:24 +0000 (12:50 +0100)] 
Move unlink_try_hard and dependents into mkosi.remove

Similar to mkosi.install but for removing things.

2 years agotests: appease pyright
Joerg Behrmann [Thu, 24 Nov 2022 11:09:20 +0000 (12:09 +0100)] 
tests: appease pyright

2 years agoMove Gentoo to DistributionInstaller
Joerg Behrmann [Wed, 23 Nov 2022 13:57:06 +0000 (14:57 +0100)] 
Move Gentoo to DistributionInstaller

2 years agoci: drop pyright version restriction
Joerg Behrmann [Tue, 22 Nov 2022 16:57:35 +0000 (17:57 +0100)] 
ci: drop pyright version restriction

2 years agoMove OpenSuse to DistributionInstaller
Joerg Behrmann [Tue, 22 Nov 2022 16:15:38 +0000 (17:15 +0100)] 
Move OpenSuse to DistributionInstaller

2 years agoMake all imports absolute
Joerg Behrmann [Tue, 22 Nov 2022 15:47:27 +0000 (16:47 +0100)] 
Make all imports absolute

2 years agoMove Debian and Ubuntu to DistributionInstaller
Joerg Behrmann [Tue, 4 Oct 2022 16:06:38 +0000 (18:06 +0200)] 
Move Debian and Ubuntu to DistributionInstaller

2 years agoMake install_skeleton_tree independent of Distribution enum
Joerg Behrmann [Tue, 4 Oct 2022 15:57:51 +0000 (17:57 +0200)] 
Make install_skeleton_tree independent of Distribution enum

Note for bisecting: This breaks skeleton tree on Debian-based distributions.

2 years agoAdd remove_packages method to DistributionInstaller
Joerg Behrmann [Tue, 4 Oct 2022 15:51:30 +0000 (17:51 +0200)] 
Add remove_packages method to DistributionInstaller

This should probably live in PackageType, but there is a strong dependence
between package type and distribution and I haven't figured out a good way to do
this without cyclical imports.

2 years agoStart moving functions that copy files into the image into a new install module
Joerg Behrmann [Sun, 18 Sep 2022 15:20:54 +0000 (17:20 +0200)] 
Start moving functions that copy files into the image into a new install module

2 years agoMove Arch install functions to distributions.arch
Joerg Behrmann [Tue, 4 Oct 2022 15:38:03 +0000 (17:38 +0200)] 
Move Arch install functions to distributions.arch

2 years agoMove functions out off __init__
Joerg Behrmann [Fri, 16 Sep 2022 17:30:13 +0000 (19:30 +0200)] 
Move functions out off __init__

Some are moved to backend for lack of a better place for now, most mount-related
functions are moved to a new mounts module, though some are left in __init__ for
later, when the dust settles and cyclic imports may become easier to avoid.

2 years agoHook up DistributionInstaller
Joerg Behrmann [Fri, 16 Sep 2022 16:33:33 +0000 (18:33 +0200)] 
Hook up DistributionInstaller

2 years agoAdd DistributionInstaller and hook it into MkosiState
Joerg Behrmann [Tue, 4 Oct 2022 14:52:44 +0000 (16:52 +0200)] 
Add DistributionInstaller and hook it into MkosiState

2 years agocli: say "(default)" not "default"
Zbigniew Jędrzejewski-Szmek [Tue, 22 Nov 2022 12:12:02 +0000 (13:12 +0100)] 
cli: say "(default)" not "default"

For partitions we use "(disabled)" so let's match the style.

2 years agoMake Distribution enum string-based
Joerg Behrmann [Tue, 4 Oct 2022 14:51:00 +0000 (16:51 +0200)] 
Make Distribution enum string-based

2 years agoMerge pull request #1249 from keszybz/verb-parameters
Jörg Behrmann [Mon, 21 Nov 2022 10:15:10 +0000 (11:15 +0100)] 
Merge pull request #1249 from keszybz/verb-parameters

Add missing descriptions of verbs which take parameters

2 years agomkosi: rework --help to print command syntax 1249/head
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:46:13 +0000 (18:46 +0200)] 
mkosi: rework --help to print command syntax

Command list and syntax is the most interesting part of the output.
But because of how argparse works, we were showing this part very
briefly and buried in other options. Instead of relying on the autogenerated
description, let's reuse the list from the man page.
Because a literal text is added, the lines for verbs and --help
and --version are suppressed.

I changed "Distribution" to "Distribution options" and so on for each
option group. The additional word connects the synopsis (which says
"[options…]" with the list below.

Output:
$ bin/mkosi --help| head -n 20
usage:
       mkosi [options...] summary
       mkosi [options...] build [script parameters...]
       mkosi [options...] shell [command line...]
       mkosi [options...] boot [nspawn settings...]
       mkosi [options...] qemu [qemu parameters...]
       mkosi [options...] ssh [command line...]
       mkosi [options...] clean
       mkosi [options...] serve
       mkosi [options...] bump
       mkosi [options...] genkey
       mkosi [options...] help
       mkosi -h | --help
       mkosi --version

Build Bespoke OS Images

Distribution options:
  -d, --distribution {fedora,debian,...

When printed on the console, summary/build/shell/… are bold.

2 years agomkosi: drop ArgumentParserMkosi.fromfile_prefix_chars
Zbigniew Jędrzejewski-Szmek [Wed, 2 Nov 2022 14:03:42 +0000 (15:03 +0100)] 
mkosi: drop ArgumentParserMkosi.fromfile_prefix_chars

mkosi is not usable as a library (all APIs are internal). So there is no need
to use a global variable for this. If we ever want to change it (and it's unlikely
that we ever would), we can just replace the character in the few places. The
code is much more readable without the indirection.

2 years agoAdd missing documentation about cmdlines for various verbs
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:27:38 +0000 (18:27 +0200)] 
Add missing documentation about cmdlines for various verbs

The error message is changed to be more direct. If somebody doesn't know that
the parameters are passed to the command, "additional" would be unclear.

In the man page the verbs are listed by the order one would normally use them,
i.e. summary, then build, then qmeu/shell/boot/…, then clean, and the less
frequently used verbs last.

Descriptions are added to the commands which take parameters that they do that
and how those parameters are interpreted. In paricular, for 'boot' we accept
kernel commandline options, and for 'qemu' we only take qemu options. (Which is
understandable, given that we don't do a direct kernel boot, but not obvious.)

Fixes #1210.

2 years agoman: regenerate man page
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:22:06 +0000 (18:22 +0200)] 
man: regenerate man page

2 years agodebian/ubuntu: Configure apt chroot with APT_CONFIG
Georges Discry [Tue, 15 Nov 2022 10:19:42 +0000 (11:19 +0100)] 
debian/ubuntu: Configure apt chroot with APT_CONFIG

When invoking apt switched from running inside the container to running
on the host, apt stopped reading the configuration files present in the
container. Because of this, it is not possible anymore to configure apt
by dropping a file in `mkosi.skeleton/etc/apt/apt.conf.d/`.

apt first loads its configuration files and then parse the command-line
options (so that they can override the options set in the files). While
setting `-o Dir=<container-root>` on the command-line has some impact on
the configuration of apt, it will not read the files in
`<container-root>/etc/apt/apt.conf.d/`, as apt has already read its
configuration files from the host with the configuration `Dir "/"`.

Rather than using the command-line, the APT_CONFIG environment variable
should be used to point to a file with the chroot configuration. When
set, that file is processed before anything else. By setting `Dir` this
way, apt will read the configuration files from the container and not
from the host.

As the host configuration is not read anymore, there is no more need to
mask `/etc/apt` on the host by bind-mounting an empty directory over it.

2 years agoUse the right python when mkosi is a symlink
Georges Discry [Tue, 15 Nov 2022 11:22:31 +0000 (12:22 +0100)] 
Use the right python when mkosi is a symlink

When the `mkosi` on the `PATH` is a symlink to the script installed
inside a virtualenv, the script fails to find the python executable
inside the virtualenv and falls back to the main python3. This is
notably the case when installing mkosi with pipx.

By first following the symlink inside the virtualenv, the script can
find the corresponding python executable.

2 years agoMerge pull request #1267 from DaanDeMeyer/fix-passing-nspawn-args
Daan De Meyer [Mon, 14 Nov 2022 17:24:04 +0000 (18:24 +0100)] 
Merge pull request #1267 from DaanDeMeyer/fix-passing-nspawn-args

Fix passing extra options to systemd-nspawn

2 years agoLook in both the config file and the cwd for dropin files 1267/head
Daan De Meyer [Mon, 14 Nov 2022 15:18:39 +0000 (16:18 +0100)] 
Look in both the config file and the cwd for dropin files

A project might have multiple config files in subdirectories that
they use with --default but have shared configuration in the root
of the repository. When loading such a config file with --default,
we should still load shared dropins from the shared location.

2 years agoFix reading dropin files
fedora Cloud User [Mon, 14 Nov 2022 15:27:38 +0000 (15:27 +0000)] 
Fix reading dropin files

When using iterdir() we don't have to join the paths anymore

2 years agoFix passing extra options to systemd-nspawn
Daan De Meyer [Mon, 14 Nov 2022 15:10:25 +0000 (16:10 +0100)] 
Fix passing extra options to systemd-nspawn

systemd-nspawn ignores all options after the first argument so when
we're passing kernel command line arguments, we need to make sure
we pass the nspawn options first, otherwise they'll get ignored.

2 years agoImplement --repository-key-check=no for dnf-based distros
reuben olinsky [Mon, 14 Nov 2022 07:10:00 +0000 (23:10 -0800)] 
Implement --repository-key-check=no for dnf-based distros

2 years agoPass KERNEL_INSTALL_BYPASS through to the places where it is used
Joerg Behrmann [Tue, 8 Nov 2022 12:46:04 +0000 (13:46 +0100)] 
Pass KERNEL_INSTALL_BYPASS through to the places where it is used

The idea of using KERNEL_INSTALL_BYPASS is to not run kernel-install twice
unnecessarily, since we run it later anyway, but a user reported a regression of
kernel-install not being run at all, although it apparently was in
earlier. Passing the environment variable through will at most run
kernel-install twice, this might be a workaround.

Fixes: #1263
2 years agoMake sure parse_args_file_group() looks in the right directory
Daan De Meyer [Mon, 7 Nov 2022 10:32:12 +0000 (11:32 +0100)] 
Make sure parse_args_file_group() looks in the right directory

We should look for dropins in the same directory as where we look
for the main config file.

2 years agoImplement clean_package_manager_metadata for pacman
LaserEyess [Sun, 6 Nov 2022 17:09:08 +0000 (12:09 -0500)] 
Implement clean_package_manager_metadata for pacman

2 years agoFlush files after copying
reuben olinsky [Thu, 3 Nov 2022 15:55:04 +0000 (08:55 -0700)] 
Flush files after copying

This resolves an issue where qemu sees an incomplete image when
--ephemeral is used.

2 years agoFix path traversal in tar extraction
Joerg Behrmann [Mon, 31 Oct 2022 09:40:58 +0000 (10:40 +0100)] 
Fix path traversal in tar extraction

This fixes CVE-2007-4559 [1], which was reported in an automated closing
campaign in PR #1253.

Crafted members of a tarfile with .. in their paths could resolve to paths
outside of the target directory to which the members would be extracted to.

[1] https://github.com/advisories/GHSA-gw9q-c7gh-j9vm

Closes: #1253
2 years agoAllow uncompressed squashfs images
reuben olinsky [Fri, 28 Oct 2022 02:51:41 +0000 (19:51 -0700)] 
Allow uncompressed squashfs images

The argument parsing was blocking this but the logic invoking
mksquashfs already supported it.

2 years agoFix input check for valid base image
Michael A Cassaniti [Tue, 1 Nov 2022 06:51:50 +0000 (17:51 +1100)] 
Fix input check for valid base image

2 years agotests: do not hardcode x86_64 as the architecture
Luca Boccassi [Sun, 30 Oct 2022 11:17:13 +0000 (11:17 +0000)] 
tests: do not hardcode x86_64 as the architecture

Otherwise tests will fail when run on other architectures.

2 years agoAdd more Debian architecture mappings
Luca Boccassi [Sat, 29 Oct 2022 13:50:41 +0000 (14:50 +0100)] 
Add more Debian architecture mappings

2 years agoMerge pull request #1246 from keszybz/print-summary-to-stdout,use-colour
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 15:22:42 +0000 (17:22 +0200)] 
Merge pull request #1246 from keszybz/print-summary-to-stdout,use-colour

Print summary to stdout, use colour

2 years agoMake load_args sideeffect free
Joerg Behrmann [Fri, 28 Oct 2022 09:00:42 +0000 (11:00 +0200)] 
Make load_args sideeffect free

It is unnecessary for the find_foo functions in load_args to generate and chown
directories, since for output and build directory this is already done by the
make_foo_dir functions in build_stuff. At a similar function for the cache
directory.

Having the find_foo functions make the directories has the downside of leading
to permission errors, when the tests are run with fakeroot as done by many
distro buildsystems.

2 years agoNEWS: more markup
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 16:12:37 +0000 (18:12 +0200)] 
NEWS: more markup

2 years agoVersion 14 v14
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 16:04:37 +0000 (18:04 +0200)] 
Version 14

2 years agomkosi: put various script-related status lines together 1246/head
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 13:13:31 +0000 (15:13 +0200)] 
mkosi: put various script-related status lines together

For some reason the build script was described quite far from the
other scripts. Since 19a989fdafe3b50b7c6629efa64e6e4b1fa0c31a the same
environment is used for all scripts, so the "Script Environment" line
is now under all scripts, since it applies to all of them.

2 years agomkosi: verify scripts after parsing config, show status in summary
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 13:01:55 +0000 (15:01 +0200)] 
mkosi: verify scripts after parsing config, show status in summary

We would refuse a script if not found or not executable immediately when
parsing the argument. But only the last specified script matters, so it's
better to delay the check: in initial parsing store the path, and later check
that it exists and matches the relevant criteria, at the time when we also
check the outputs.

Similarly for tree inputs: they are checked at this time too.
This fixes #1167.

Instead of trying to generate error messages, just reuse normal Python
exceptions: i.e. os.access() is replaced by open(). This way we don't need to
come up with error messages for various conditions and possibly get them wrong.

Rework status command to show status of inputs and scripts:

$ bin/mkosi --extra-tree={./missing,/root/inaccessible} --{prepare,build,finalize,postinst}-script=/etc/fstab summary
COMMANDS:
                      verb: summary
                   cmdline:
...
CONTENT:
               Extra Trees: /home/zbyszek/src/mkosi/missing (No such file or directory)
                            /root/inaccessible (Permission denied)
            Skeleton Trees: none
...
              Build Script: /etc/fstab (Not executable)
...
        Postinstall Script: /etc/fstab (Not executable)
            Prepare Script: /etc/fstab (Not executable)
           Finalize Script: /etc/fstab (Not executable)
...

Colors are used to draw the eye to the problematic lines.

2 years agomkosi: use normal print stmts for summary
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 10:03:18 +0000 (12:03 +0200)] 
mkosi: use normal print stmts for summary

This is simpler and writes to stdout as we should, not stderr.

2 years agoMerge pull request #1151 from qdeslandes/map_permissions
Jörg Behrmann [Thu, 27 Oct 2022 11:01:44 +0000 (13:01 +0200)] 
Merge pull request #1151 from qdeslandes/map_permissions

Implement support for generated files ownership management.

2 years agoMerge pull request #1243 from keszybz/argparse-tweaks
Daan De Meyer [Thu, 27 Oct 2022 10:55:16 +0000 (12:55 +0200)] 
Merge pull request #1243 from keszybz/argparse-tweaks

Disallow option abbreviations and stop dumping usage information on error

2 years agoUpdate NEWS.md 1151/head
Quentin Deslandes [Thu, 27 Oct 2022 09:54:30 +0000 (11:54 +0200)] 
Update NEWS.md

2 years agoUse nspawn's rootidmap option for --bind mount
Quentin Deslandes [Tue, 18 Oct 2022 17:11:42 +0000 (19:11 +0200)] 
Use nspawn's rootidmap option for --bind mount

Bind-mount directories with nspawn's rootidmap option to prevent files
ownership discrepancies: files (and directories) created from within the
container in the mounted directory will be owned by the owner of the
directory on the backing filesystem.

This means, mkosi-generated directories and owner by any other user that
root won't be polluted by root-owned files and folders once the
container is stopped.

2 years agochown mkosi-generated directories
Quentin Deslandes [Tue, 18 Oct 2022 17:10:32 +0000 (19:10 +0200)] 
chown mkosi-generated directories

Change the owner of directories created by mkosi, unless --no-chown is
used. Directories owner will be set to SUDO_UID or PKEXEC_UID if
defined, or to current UID otherwise.

2 years agoAdd --noplugins when calling dnf
Daan De Meyer [Thu, 27 Oct 2022 08:09:45 +0000 (10:09 +0200)] 
Add --noplugins when calling dnf

Let's isolate image builds using dnf from the host a bit more by
disabling all plugins. For example, plugins such as versionlock
can interfere with the version of packages installed in the image
which we want to avoid.

2 years agomkosi: supress printing of argparse help on error 1243/head
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:39:11 +0000 (10:39 +0200)] 
mkosi: supress printing of argparse help on error

We build a precise error message, but then bury it under a wall of text
produced by print_usage(). The printing of help (or some subset of it) on
parsing error is just useless. Most likely the user made a typo in an option,
and printing a few dozen lines (and more in the future) of unhelpful
semi-related information is counterproductive.

I'm surprised that argparse doesn't make this configurable, but looking at the
code, it seems that the behaviour is hardcoded. Docs and stackoverflow also
yield no hints.

2 years agomkosi: disallow parameter abbreviations
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:31:37 +0000 (10:31 +0200)] 
mkosi: disallow parameter abbreviations

For interactive use, we have both short options and tab-completion.
Abbreviated options are problematic because of forward-compatibility:
if we add more options in the future, an older abbreviation might become
non-unique and stop working.

2 years agomkosi: do not build a temporary dictionary for kwargs
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:27:19 +0000 (10:27 +0200)] 
mkosi: do not build a temporary dictionary for kwargs

Let's use the usual method for passing mixed inherited and local keyword args.
We don't need to put the argument names in quotes so this looks nicer. Also,
if we were to make a mistake and pass the same kwargs in two places, previously
the local assignment would silently override the other value. But that seems
inverted because now the base class overwrites something specified by the daughter
class. Anyway, it's better to throw an error, which we now will do:

TypeError: argparse.ArgumentParser.__init__() got multiple values for keyword argument '…'