]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
6 years agomypy: Fix issues discovered by mypy 300/head
Luke Shumaker [Sun, 2 Dec 2018 07:46:22 +0000 (02:46 -0500)] 
mypy: Fix issues discovered by mypy

Mostly issues with not handling things that may be None.

6 years agomypy: Fiddle with things to clue mypy in
Luke Shumaker [Sun, 2 Dec 2018 10:05:09 +0000 (05:05 -0500)] 
mypy: Fiddle with things to clue mypy in

But this shouldn't actually change anything; this is just making
stylistic changes to the code to clue mypy in to some stuff.

6 years agomypy: Unify typing of install_distribution() and install_{DISTRIBUTION}()
Luke Shumaker [Sun, 2 Dec 2018 16:51:05 +0000 (11:51 -0500)] 
mypy: Unify typing of install_distribution() and install_{DISTRIBUTION}()

6 years agomypy: invoke_dnf_or_yum(): Match the signature of invoke_dnf() and invoke_yum()
Luke Shumaker [Sun, 2 Dec 2018 16:43:52 +0000 (11:43 -0500)] 
mypy: invoke_dnf_or_yum(): Match the signature of invoke_dnf() and invoke_yum()

6 years agomypy: ListAction: assert that 'values' is a string
Luke Shumaker [Sun, 2 Dec 2018 19:01:00 +0000 (14:01 -0500)] 
mypy: ListAction: assert that 'values' is a string

We must declare 'values' as Union[str, Sequence[Any], None], to keep the
__call__ definition compatible with the parent class.  However, we know
(and rely on) that how we call .add_argument() means that it will always
be a str.  Add an 'assert' to let mypy know what we know.

6 years agomypy: Make arguments Optional[], assert is not None as appropriate
Luke Shumaker [Sun, 2 Dec 2018 18:38:46 +0000 (13:38 -0500)] 
mypy: Make arguments Optional[], assert is not None as appropriate

There are several places where we unconditionally call a function, then
that function checks `args` to decide if it immediately returns, or if it
actually gets to do work.  In the cases where it immediately returns, some
of the arguments can be None, so they should be hinted as Optional[].
However, in the case were it does get to do work, they cannot be None.

So, hint them as Optional[], and the add `assert ARGNAME is not None`
after the check that implies it's not None, to let mypy know what we know.

For instance: args.output_format.is_disk() implies that raw is not None.
So it's safe to make the change:

         if not args.output_format.is_disk():
             return None
    +    assert raw is not None

6 years agomypy: Add missing type annotations
Luke Shumaker [Sun, 2 Dec 2018 07:20:12 +0000 (02:20 -0500)] 
mypy: Add missing type annotations

6 years agomypy: Fix wrong type annotations
Luke Shumaker [Sun, 2 Dec 2018 18:38:03 +0000 (13:38 -0500)] 
mypy: Fix wrong type annotations

Common cases:

 - An `if foo is None` check clearly indicates that foo should be
   Optional[]:
   * prepare_root(): dev
   * prepare_home(): dev
   * prepare_srv(): dev
   * mount_image(): loopdev, home_dev, srv_dev
   * save_cache(): raw, cache_path
   * link_output_nspawn_settings(): path
   * link_output_checksum(): checksum
   * link_output_root_hash(): root_hash_file
   * link_output_signature(): signature
   * link_output_bmap(): bmap
   * process_settings(): key
   * run_build_script(): raw
 - In general, replace IO[str] with TextIO, except that in many cases
   BinaryIO is correct:
   * create_image() returns binary, not text
   * reuse_cache_image() returns binary, not text
   * attach_image_loopback() takes binary, not text
   * make_verity() returns binary, not text
   * calculate_sha256sum():
     . argument: raw is binary, not text
     . argument: tar is binary, not text
   * make_build_dir():
     . return: (raw|squashfs) is binary, not text
     . return: tar is binary, not text
   * run_build_script(): raw is binary, not text
   * remove_artifacts():
     . argument: raw is binary, not text
     . argument: tar is binary, not text
 - In general, replace IO[bytes] with BinaryIO, except that in many cases
   TextIO is correct:
    * calculate_sha256sum() returns text, not binary
    * calculate_bmap() returns text, not binary
 - Avoid ambiguous IO[Any]:
    * hash_file() writes to a TextIO
    * calculate_bmap() reads a BinaryIO

Special cases:

 - run(): Either returns a CompletedProcess, or doesn't return.  Drop
   the Optional[].
 - mount_image(): ???
 - calculate_sha256sum():
   . argument: root_hash_file is a BinaryIO, not a str
   . argument: nspawn_settings is a BinaryIO, not a str
     Wait, BinaryIO, not TextIO!?  Yes, even though the .nspawn file is
     plaintext.  The IO object we have here is a NamedTemporaryFile copy
     of the user's .nspawn file.  We made that copy in binary mode, to
     avoid pointlessly decoding then encoding the text.
 - remove_glob(): When providing a type hint for '*args', you provide the
   hint for the individual 'arg's, not the 'args' list.

6 years agomypy: Change GPTRootTypePair: collections.namedtuple → typing.NamedTuple
Luke Shumaker [Sun, 2 Dec 2018 16:40:31 +0000 (11:40 -0500)] 
mypy: Change GPTRootTypePair: collections.namedtuple → typing.NamedTuple

6 years agomypy: Create new variables instead of reusing names
Luke Shumaker [Sun, 2 Dec 2018 07:45:04 +0000 (02:45 -0500)] 
mypy: Create new variables instead of reusing names

When we have a "new" with a new type, don't reuse the name of another
variable still in scope.

6 years agomypy: Figure out generators and decorators
Luke Shumaker [Sun, 2 Dec 2018 16:19:37 +0000 (11:19 -0500)] 
mypy: Figure out generators and decorators

 - A @contextlib.contextmanager should return a
   typing.Generator[yield, send, return]
 - Because of <https://github.com/python/mypy/issues/1317>, mypy 0.641
   doesn't think complete_step() has the correct type to be a decorator
   that works the way it does.  So, set

       completestep = complete_step

   But do typecasting to make mypy think it's the correct type.  And use
   `@completestep` instead of `@complete_step`.  That's an easy
   search/replace.

6 years agomypy: Fiddle with making it happy with argcomplete
Luke Shumaker [Sun, 2 Dec 2018 06:46:42 +0000 (01:46 -0500)] 
mypy: Fiddle with making it happy with argcomplete

6 years agomypy: Differentiate partition() from optional_partition()
Luke Shumaker [Wed, 7 Nov 2018 19:46:25 +0000 (14:46 -0500)] 
mypy: Differentiate partition() from optional_partition()

6 years agomypy: Introduce manual cast()s around tempfile.NamedTemporaryFile
Luke Shumaker [Sun, 2 Dec 2018 06:41:38 +0000 (01:41 -0500)] 
mypy: Introduce manual cast()s around tempfile.NamedTemporaryFile

Unfortunately, mypy 0.641 isn't yet smart enough to figure out the
appropriate subtype of IO to return from tempfile.NamedTemporaryFile()
based on whether the mode= argument contains "b", so we'll have to cast()
its return value for now.

If this makes a line wider than 119 characters, move the dir= argument to
the next line.

6 years agomypy: Convert type-hint comments to PEP 526 type-hints
Luke Shumaker [Wed, 7 Nov 2018 15:14:38 +0000 (10:14 -0500)] 
mypy: Convert type-hint comments to PEP 526 type-hints

Commit a415718e27b673032a415d35af41f9d3aa1b9a99 bumped the required
Python version to 3.6; which means that we can now use PEP 526
type-hints, instead of doing it in magical `# type:` comments.

6 years agomypy: .gitignore: Add .mypy_cache/
Luke Shumaker [Sun, 2 Dec 2018 10:01:28 +0000 (05:01 -0500)] 
mypy: .gitignore: Add .mypy_cache/

6 years agoflake8: E741: Rename ambiguous variable
Luke Shumaker [Sun, 2 Dec 2018 05:37:03 +0000 (00:37 -0500)] 
flake8: E741: Rename ambiguous variable

PEP 8 says to avoid `l` as a variable name, because it can be hard to
distinguish from `1` and `I`.  This means that flake8 complains about
the variable inside of ListAction.

However, flake8 doesn't trigger E741 for *argument* names.  Even
though flake8 doesn't complain about it, also rename the argument of
line_join_list() from `l` to `ary`.

6 years agoflake8: E722: Ignore complaints about bare 'except'
Luke Shumaker [Sun, 2 Dec 2018 05:36:27 +0000 (00:36 -0500)] 
flake8: E722: Ignore complaints about bare 'except'

6 years agoflake8: F401: Remove unused import
Luke Shumaker [Sun, 2 Dec 2018 05:35:47 +0000 (00:35 -0500)] 
flake8: F401: Remove unused import

6 years agoflake8: E703: Remove pointless semicolons
Luke Shumaker [Sun, 2 Dec 2018 05:12:31 +0000 (00:12 -0500)] 
flake8: E703: Remove pointless semicolons

6 years agoflake8: E111,E128: Fixup indentation
Luke Shumaker [Sun, 2 Dec 2018 05:06:36 +0000 (00:06 -0500)] 
flake8: E111,E128: Fixup indentation

 - E111: Normal indents should be multiples of 4
 - E128: Fixup visual indents

6 years agoflake8: E201,E202,E203,E221,E222,E251: Remove individual spaces around things
Luke Shumaker [Sun, 2 Dec 2018 05:35:32 +0000 (00:35 -0500)] 
flake8: E201,E202,E203,E221,E222,E251: Remove individual spaces around things

 - E201: Don't put a space after the `[` in a list:
       ary = [ item,
              ^
 - E201: Don't put a space after the `{` in a dict:
       d = { key: val,
            ^
 - E202: Don't put a space before the `]` in a list:
       ary = [item1, item2 ]
                          ^
 - E202: Don't put a space before the `}` in a dict:
       d = [key: val }
                    ^
 - E203: Don't put a space before the `:` in a dict:
       d = {key : val}
               ^
 - E221: Write `# NOQA: E221` if we're lining up the `=` in a list of
   assignments
 - E222: Write `# NOQA: E222` if we're lining numbers on the right
   side of `=` in a list of assignments
 - E251: When defining an argument a default value, and the argument
   isn't type-hinted, don't put spaces around the `=`:
       def fn(argname = default) -> type:
                     ^ ^
   This is in contrast with type-hinted arguments with defaults, which
   DO get spaces around the `=` (E252).
 - E251: Don't put spaces around the `=` when passing a keyword
   argument to a function:
       fn(kw = val)
            ^ ^

6 years agoflake8: E225,E227,E231,E252,E261: Add individual spaces around things
Luke Shumaker [Sun, 2 Dec 2018 05:04:12 +0000 (00:04 -0500)] 
flake8: E225,E227,E231,E252,E261: Add individual spaces around things

 - E225: Put a space on each side of the `+` operator
 - E227: Put a space on each side of the `|` operator
 - E227: Put a space on each side of the `<<` operator
 - E231: Put a space after `,` in a list/set/tuple.
 - E231: Put a space after the `:` when defining a lambda
 - E231: Put a space after the `:` in dict literals
 - E231: When type-hinting an argument, put a space between the `:`
   and the type:
       def fn(argname: type) -> type:
                      ^
 - E252: When type-hinting an argument with a default value, put
   spaces around the `=`:
       def fn(argname: type = default) -> type:
                           ^ ^
   This is in contrast with non-type-hinted arguments with defaults,
   which do NOT get spaces around the `=` (E251).
 - E261: Put two spaces before the `#` of an inline comment

6 years agoflake8: E301: At least 1 blank line between method definitions
Luke Shumaker [Sun, 2 Dec 2018 04:47:34 +0000 (23:47 -0500)] 
flake8: E301: At least 1 blank line between method definitions

6 years agoflake8: E302,E305: 2 blank lines around class/function definitions
Luke Shumaker [Sun, 2 Dec 2018 04:45:06 +0000 (23:45 -0500)] 
flake8: E302,E305: 2 blank lines around class/function definitions

This does not apply to method definitions.

6 years agoflake8: E501: Address lines that are 120 characters or longer
Luke Shumaker [Sun, 2 Dec 2018 04:27:16 +0000 (23:27 -0500)] 
flake8: E501: Address lines that are 120 characters or longer

 - Set the maximum line length to 119, same as systemd.git
 - If the line is a function definition that is long because of many args,
   put one arg per line
 - Don't split user-facing strings over multiple lines; use NOQA to silence
   those complaints
 - In a few cases, re-structure the code to be easier to follow

This doesn't blindly modify the code to flake8's complaints, it looks at
long lines, and sees if we can make them easier to read.

6 years agoflake8-isort: Run `isort *.py`
Luke Shumaker [Sun, 2 Dec 2018 03:50:14 +0000 (22:50 -0500)] 
flake8-isort: Run `isort *.py`

And add `setup.cfg` to configure isort.

6 years agoAvoid multi-line lambdas; use a regular `def` in those cases
Luke Shumaker [Sun, 2 Dec 2018 05:13:58 +0000 (00:13 -0500)] 
Avoid multi-line lambdas; use a regular `def` in those cases

They are hard to read.

6 years agoMerge pull request #298 from lucasdemarchi/tip-fix-arch
Lucas De Marchi [Fri, 30 Nov 2018 22:05:26 +0000 (14:05 -0800)] 
Merge pull request #298 from lucasdemarchi/tip-fix-arch

Fix non-bootable Arch images

6 years agoFix package manager cleanup
Lucas De Marchi [Thu, 29 Nov 2018 22:45:12 +0000 (14:45 -0800)] 
Fix package manager cleanup

As the cache is still mounted when we try to cleanup the metadata, it
was removing the downloaded packages from mkosi.cache (or whatever path
the user specified).

Tested Fedora only, with multiple invocations of

    touch mkosi.cache

and multiple invocations of

    sudo mkosi -f --default /dev/null  -d fedora -r 29
    find mkosi.cache -name '*.rpm'

6 years agoFix non-bootable Arch images 298/head
Lucas De Marchi [Thu, 29 Nov 2018 23:29:59 +0000 (15:29 -0800)] 
Fix non-bootable Arch images

6 years agoMerge pull request #261 from rantogno/legacy_boot
Lennart Poettering [Wed, 21 Nov 2018 10:45:42 +0000 (11:45 +0100)] 
Merge pull request #261 from rantogno/legacy_boot

Add BootProtocols option

6 years agoset correct defaults for optional args
Thore Bödecker [Tue, 20 Nov 2018 13:19:32 +0000 (14:19 +0100)] 
set correct defaults for optional args

args.with_network and args.with_docs were always initialized to `False`
thus ignoring any setting in a config file (WithNetwork/WithDocs).

This breaks the config parser (load_defaults) because it checks if the
current value of `key` is None before assigning the value from the
config file.

Signed-off-by: Thore Bödecker <me@foxxx0.de>
6 years agoAdd bios support to Archlinux 261/head
Lucas De Marchi [Sat, 17 Nov 2018 00:24:18 +0000 (16:24 -0800)] 
Add bios support to Archlinux

In order to add support to boot on bios mode for Archlinux, the
following changes were made:

    - kernel packages are now installed as a second step: this allows us
      to patch the initrd config file so to disable the autodetection
      hook
    - patching the initrd config is now part of the distro install
      rather than bootloader install

uefi-only is the default and we can generate uefi-only, bios-only and
hybrid images. In the latter case grub is used for bios and systemd-boot
for UEFI.

6 years agoMove grub config generation to grub installation
Lucas De Marchi [Fri, 16 Nov 2018 09:25:11 +0000 (01:25 -0800)] 
Move grub config generation to grub installation

This allows it to be compatible with distros that ship a default configuration
file. Now we patch the file if it exits, or create one otherwise.

6 years agoAdd support to boot on bios
Rafael Antognolli [Tue, 6 Nov 2018 16:30:10 +0000 (08:30 -0800)] 
Add support to boot on bios

This implements boot on systems with legacy bios rather
than UEFI. It works by installing grub-pc and systemd-boot
side by side. The former is responsible for bios boot while
the latter continues to be the bootloader for UEFI.

The resulting image, that is currently working only on Fedora,
is capable of booting on both systems. Generate the image with:

    $ sudo mkosi -d fedora -r 29 -t raw_ext4 -b --boot-protocols uefi bios

Boot with UEFI:

    $ sudo qemu-system-x86_64 -machine accel=kvm -smp 2 -m 1024 \
        -drive if=pflash,format=raw,readonly,file=/usr/share/edk2/ovmf/OVMF_CODE.fd \
        -drive format=raw,file=image.raw

Boot with bios:

    $ sudo qemu-system-x86_64 -machine accel=kvm -smp 2 -m 1024 \
        -drive format=raw,file=image.raw

Lucas: This is a cleanup of the implementation done by Rafael
and allowing to have the hybrid approach rather than mandating one
or the other.

6 years agoAdd option for boot protocols
Lucas De Marchi [Thu, 1 Nov 2018 05:27:46 +0000 (22:27 -0700)] 
Add option for boot protocols

This will allow us to install different boot protocols like
UEFI, BIOS and possibly others.

6 years agoMerge pull request #284 from lucasdemarchi/tip-chown
Lennart Poettering [Mon, 19 Nov 2018 13:43:02 +0000 (14:43 +0100)] 
Merge pull request #284 from lucasdemarchi/tip-chown

chown output files to the calling user

6 years agoMerge pull request #290 from jimenezrick/master
Lennart Poettering [Mon, 19 Nov 2018 13:41:44 +0000 (14:41 +0100)] 
Merge pull request #290 from jimenezrick/master

Add back again the ovmf firmware path from Arch Linux

6 years agomkosi: Add back again the ovmf firmware path from Arch Linux 290/head
Ricardo Catalinas Jiménez [Sat, 17 Nov 2018 17:59:24 +0000 (17:59 +0000)] 
mkosi: Add back again the ovmf firmware path from Arch Linux

Currently works fine in Arch Linux.

6 years agoREADME.md: update deprecated flags - raw_* -> gpt_*
Ricardo Catalinas Jiménez [Sat, 17 Nov 2018 17:57:45 +0000 (17:57 +0000)] 
README.md: update deprecated flags - raw_* -> gpt_*

Plus fix the typo to specify the Arch Linux distro as `arch`.

6 years agoMerge pull request #288 from foxxx0/fix-centos-build
Lucas De Marchi [Tue, 13 Nov 2018 21:12:35 +0000 (13:12 -0800)] 
Merge pull request #288 from foxxx0/fix-centos-build

include args.packages for centos builds

6 years agoinclude args.packages for centos builds 288/head
Thore Bödecker [Tue, 13 Nov 2018 13:04:26 +0000 (14:04 +0100)] 
include args.packages for centos builds

6 years agoFix function signature for Clear
Lucas De Marchi [Mon, 12 Nov 2018 18:23:57 +0000 (10:23 -0800)] 
Fix function signature for Clear

  File "/usr/lib64/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
TypeError: install_clear() takes 1 positional argument but 2 positional arguments (and 2 keyword-only arguments) were given

6 years agoMake chown of output files optional 284/head
Lucas De Marchi [Mon, 12 Nov 2018 18:58:27 +0000 (10:58 -0800)] 
Make chown of output files optional

6 years agoChown output files to user calling sudo
Lucas De Marchi [Wed, 7 Nov 2018 18:55:56 +0000 (10:55 -0800)] 
Chown output files to user calling sudo

In most of the cases we are using sudo to elevate privileges and be able
to do all operations we need. The final files created by mkosi though
should better be owned by the original user so the user may decide what
to do with it like copying it somewhere else, starting qemu, etc.

6 years agoAdd helper function to link output files
Lucas De Marchi [Wed, 7 Nov 2018 17:41:41 +0000 (09:41 -0800)] 
Add helper function to link output files

6 years agoMerge pull request #286 from poettering/test-ci
Lucas Werkmeister [Mon, 12 Nov 2018 10:17:54 +0000 (11:17 +0100)] 
Merge pull request #286 from poettering/test-ci

Add support for building mkosi with semaphore CI

6 years agoci: add simple script for running CI tests in semaphore 286/head
Lennart Poettering [Sun, 11 Nov 2018 20:05:43 +0000 (21:05 +0100)] 
ci: add simple script for running CI tests in semaphore

For now, it just builds an Ubuntu image

6 years agomkosi: use debootstrap's --merged-usr switch only if supported
Lennart Poettering [Sun, 11 Nov 2018 20:04:22 +0000 (21:04 +0100)] 
mkosi: use debootstrap's --merged-usr switch only if supported

This allows us to run mkosi on Semaphore, which only provides us with
Ubuntu 16.04 as newest release, where this swich isn't known yet.

6 years agoBump required Python version everywhere
Lucas Werkmeister [Sat, 10 Nov 2018 11:43:01 +0000 (12:43 +0100)] 
Bump required Python version everywhere

The required Python version was bumped to 3.6 in e965e58a3f (because we
now use f-strings), but README.md and setup.py weren’t updated.

6 years agoMerge pull request #283 from keszybz/f-strings
Lennart Poettering [Tue, 6 Nov 2018 21:53:14 +0000 (00:53 +0300)] 
Merge pull request #283 from keszybz/f-strings

Use f-strings and some minor cleanups

6 years agoBump required python version to 3.6 283/head
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 21:44:35 +0000 (22:44 +0100)] 
Bump required python version to 3.6

f-strings are a syntax error with older versions anyway, but let's bump
the version string for any human readers.

6 years agoAdd mkosi.py as symlink to mkosi
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 16:52:49 +0000 (17:52 +0100)] 
Add mkosi.py as symlink to mkosi

This is useful during development to allow 'import mkosi', for
example to test import functions and such. In the future it'll also
be useful if we grow any unittests.

6 years agoUse f-strings
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 16:35:26 +0000 (17:35 +0100)] 
Use f-strings

I kept or switched to .format in a few places where the arguments were
more complicated.

6 years agoRemove left-over debug statement
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 16:14:19 +0000 (17:14 +0100)] 
Remove left-over debug statement

6 years agoFix arch reference in error message
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 16:08:03 +0000 (17:08 +0100)] 
Fix arch reference in error message

6 years agoMerge pull request #281 from keszybz/snap-support
Lennart Poettering [Tue, 6 Nov 2018 16:20:22 +0000 (19:20 +0300)] 
Merge pull request #281 from keszybz/snap-support

Missing bits to allow snaps to be generated using mkosi

6 years agoMerge pull request #282 from lucasdemarchi/tip-fixes
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 15:59:09 +0000 (16:59 +0100)] 
Merge pull request #282 from lucasdemarchi/tip-fixes

Fixes for latest merges

6 years agoCall 'mkosi.finalize' script 281/head
Zbigniew Jędrzejewski-Szmek [Sun, 4 Nov 2018 13:17:55 +0000 (14:17 +0100)] 
Call 'mkosi.finalize' script

This is similar to 'mkosi.postinst', but is called in the host. This
makes it much easier to copy-in files. It is also much quicker when
creating images for a foreign architecture.

v2:
- s/postinst2/finalize/g
- call the script first with "build" too
- pass the root directory as $BUILDROOT (like rpmbuild) and not as
  a positional argument. (This is easier to consume for scripts and
  also easier to extend with additional variables in the future.)
- update to use args_find_path()

6 years agoAllow forcing the installation architecture
Zbigniew Jędrzejewski-Szmek [Thu, 25 Oct 2018 16:05:05 +0000 (18:05 +0200)] 
Allow forcing the installation architecture

v2:
- s/arch/architecture/g
- add an optional line in the status output

6 years agoMake mksquashfs args configurable
Zbigniew Jędrzejewski-Szmek [Mon, 22 Oct 2018 07:42:41 +0000 (09:42 +0200)] 
Make mksquashfs args configurable

For example, snaps have to be generated with "-noappend -no-xattrs
-no-fragments -comp xz". The last argument is configurable through
Compress=xz, but the other ones weren't so far. Let's just override the
mksquashfs executable. To be nice and flexible, 'mkosi.mksquashfs-tool'
will be autodetected. It may be also specified explicitly:

  [Output]
  Mksquashfs=/some/special/mksquashfs

If specfied explicitly, an argument list may be included:

  [Output]
  Mksquashfs=mksquashfs -noappend -no-xattrs -no-fragments

When args are present, they replace "-noappend" that we add by default.
The arguments for compression (-comp xx) is always added if configured
by Compress=. This makes the two settings orthogonal.

6 years agoUse a common helper function to discover paths
Zbigniew Jędrzejewski-Szmek [Tue, 6 Nov 2018 12:02:51 +0000 (13:02 +0100)] 
Use a common helper function to discover paths

This is actually more readable because the variable name definitions
and paths are defined at one place and not spread over all the itty
bitty functions.

I used '' for the variable names and "" for paths. I think that makes
the two types of arguments a bit more distinguishable.

6 years agoFix wrong type to link_output 282/head
Lucas De Marchi [Tue, 6 Nov 2018 08:25:36 +0000 (00:25 -0800)] 
Fix wrong type to link_output

$ sudo mkosi --default /dev/null -d fedora -r 29 -t directory -p dnf
...
Traceback (most recent call last):
  File "/bin/mkosi", line 3959, in <module>
    main()
  File "/bin/mkosi", line 3949, in main
    build_stuff(args)
  File "/bin/mkosi", line 3809, in build_stuff
    link_output(args, workspace, raw or tar)
  File "/bin/mkosi", line 2478, in link_output
    os.rename(os.path.join(workspace, "root"), args.output)
  File "/usr/lib64/python3.7/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not TemporaryDirectory

6 years agoFix broken bootable images
Lucas De Marchi [Mon, 5 Nov 2018 22:13:35 +0000 (14:13 -0800)] 
Fix broken bootable images

We need to bring in systemd-udev to the packages list if the image is
bootable, not if we are going to run the build script.

$ sudo mkosi -d fedora -r 29 -t raw_ext4 -b
...
FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/mkosi-a9r063jq/root/usr/lib/systemd/boot/efi/systemd-bootx64.efi'

This could maybe be in make_rpm_list(), but the packages names for
Mageia are different than the ones for Centos/Fedora.

6 years agoRevert "Remove now-redundant check if partno is None"
Lucas De Marchi [Mon, 5 Nov 2018 22:14:04 +0000 (14:14 -0800)] 
Revert "Remove now-redundant check if partno is None"

This reverts commit 13052e658e95c5913bc11c9398faf24e60143d88.

luks_setup_all() depends on this function returning None in case
partno is None. Fixing it in the caller overly complicates it.
Let's fix the breakage and maybe later rework the code.

$ sudo mkosi -d fedora -r 29 -t raw_ext4 -b
...
subprocess.CalledProcessError: Command '['mkfs.ext4', '-L', 'home', '-M', '/home', '/dev/loop0pNone']' returned non-zero exit status 1.

To avoid the mistake again, annotate partno parameter as being
optional.

6 years agoMerge pull request #275 from keszybz/squashfs
Lennart Poettering [Sat, 3 Nov 2018 08:22:16 +0000 (11:22 +0300)] 
Merge pull request #275 from keszybz/squashfs

Plain squashfs image output and making final images leaner

6 years agogitignore: add password file and mypy cache 275/head
Zbigniew Jędrzejewski-Szmek [Wed, 31 Oct 2018 16:45:56 +0000 (17:45 +0100)] 
gitignore: add password file and mypy cache

6 years agodnf: use a shorter form for nodocs
Zbigniew Jędrzejewski-Szmek [Thu, 25 Oct 2018 15:55:46 +0000 (17:55 +0200)] 
dnf: use a shorter form for nodocs

6 years agofedora/centos: do no install systemd and passwd by default
Zbigniew Jędrzejewski-Szmek [Mon, 22 Oct 2018 09:51:36 +0000 (11:51 +0200)] 
fedora/centos: do no install systemd and passwd by default

There is no reason to require passwd to be installed. Depending on
what the image is used for, user logins through with traditional
authentication might be completely unnecessary. Similarly, systemd is
only useful when the image is to be booted (under qemu or as a
container). But when args.bootable is true, systemd-udev will pull in
systemd anyway. So let's just reduce the packages we always pull in to
the minimum that defines each distro. Any additional packages should
be pulled in through the project configuration.

6 years agoRemove yum/dnf/rpm metadata after installation
Zbigniew Jędrzejewski-Szmek [Mon, 22 Oct 2018 09:13:23 +0000 (11:13 +0200)] 
Remove yum/dnf/rpm metadata after installation

Dnf data is removed if dnf is not installed into the image, and similarly
for the other tools.

I didn't implement this functionality for Debian/Ubuntu/Arch, because I
don't know enough about those distros, but is should be easy to add.

The arguments that are passwd to build_image() and friends are made
keyword-only. There's now three arguments, and this way there's less
chance of mistake.

v2:
- When deciding whether to keep dnf or rpm data, check if path exists

Checking if the dnf/rpm packages are in the requested list is nice,
but inadequate. For example, somebody could specifyg a @group or just
another package that pulls those in. Checking if the executables are
present in the image would work in those cases too.

6 years agoRework how dnf/yum package list is generated
Zbigniew Jędrzejewski-Szmek [Mon, 22 Oct 2018 08:18:44 +0000 (10:18 +0200)] 
Rework how dnf/yum package list is generated

Two obvious bugs are fixed:
- boot_packages were always used, because run_build_script was used in a
conditional, but this name wasn't a local variable but the global function, so
it was always true ('run_build_script=True|False' wasn't passed down properly
to invoke_yum()/invoke_dnf()).
- in invoke_yum() xfsprogs wasn't added like in install_dnf().

Generating the list of packages first instead of interleaving that with
other args seems cleaner and easier to debug. The code to do that is now
shared between yum and dnf.

6 years agoRemove empty line at the beggining of functions
Zbigniew Jędrzejewski-Szmek [Sun, 21 Oct 2018 18:01:28 +0000 (20:01 +0200)] 
Remove empty line at the beggining of functions

Some functions had it, without any apparent pattern. Normal Python
coding style does not include this.

6 years agoWith --shell, pass --read-only through to systemd-nspawn
Zbigniew Jędrzejewski-Szmek [Sun, 21 Oct 2018 17:32:24 +0000 (19:32 +0200)] 
With --shell, pass --read-only through to systemd-nspawn

It seems systemd-nspawn has a bug where --read-only doesn't actually
work, but this should not hurt in either case.

Edit: https://github.com/systemd/systemd/pull/10481 for systemd-nspawn.

6 years agoMake compression type configurable
Zbigniew Jędrzejewski-Szmek [Sun, 21 Oct 2018 17:19:37 +0000 (19:19 +0200)] 
Make compression type configurable

This allows the in-fs compression algorithm to be selected: e.g. zstd
is better in pretty much all cases than zlib or xz. Lz4 might be a
good choice if speed is very important, etc.

Exact algorithms supported by both the tools and the kernel vary, so only
a general check if the algorithm name is known is done.

Note: support for zstd was added to fs/squahsfs in linux v4.13-rc5-4-g87bf54bb43.
But it seems that mksquashfs in F28 does not support zstd. Strange.

6 years agoDo not ignore negative command-line switches
Zbigniew Jędrzejewski-Szmek [Sun, 21 Oct 2018 16:26:15 +0000 (18:26 +0200)] 
Do not ignore negative command-line switches

"is None" should be used, otherwise setting something to "no" on the command-line
would be overwritten by the defaults file.

6 years agoAdd -t squasfsh: raw squashfs filesystems
Zbigniew Jędrzejewski-Szmek [Sun, 21 Oct 2018 13:00:50 +0000 (15:00 +0200)] 
Add -t squasfsh: raw squashfs filesystems

v2:
- rename 'squashfs' to 'plain_squashfs'
- add .is_squashfs() helper

6 years agoRename RAW_FORMATS to is_disk() and RAW_RW_FS_FORMATS to is_disk_rw()
Zbigniew Jędrzejewski-Szmek [Fri, 19 Oct 2018 13:21:08 +0000 (15:21 +0200)] 
Rename RAW_FORMATS to is_disk() and RAW_RW_FS_FORMATS to is_disk_rw()

The new names actually reflect the meaning. I chose "is_disk" over
"is_gpt" because it is more general and will also work if we decide to
generate other disk formats, e.g. ISO images or disks with DOS
partitions.

6 years agoRename --format members from raw_* to gpt_*
Zbigniew Jędrzejewski-Szmek [Fri, 19 Oct 2018 13:13:35 +0000 (15:13 +0200)] 
Rename --format members from raw_* to gpt_*

They are not "raw" in any meaningful way, since the filesystems are
packaged in a disk image with a gpt partition. I know that "raw" comes
from qemu, where it used to mean e.g. not-qcow2, but since we don't
produce qcow2 or any of the other formats, here it is just misleading.

Also, use auto() to number OutputFormat members and don't show compat names
in help output.

v2:
- add .__repr__() and .__str__() and .from_string() to make the --help
  output message and the error message when an unknown type is given nicer.

6 years agoAdd --debug=run
Zbigniew Jędrzejewski-Szmek [Fri, 19 Oct 2018 12:47:14 +0000 (14:47 +0200)] 
Add --debug=run

The option is written in a way that allows additional selectors to be added
easily. This patch adds just one: --debug=run, that simply prints all commands
as they are executed similarly to make.

6 years agoRemove workaround to always install docs
Zbigniew Jędrzejewski-Szmek [Fri, 19 Oct 2018 11:36:27 +0000 (13:36 +0200)] 
Remove workaround to always install docs

It was added in cf359facaeb with no explanation. Should be OK nowadays.

6 years agoMerge pull request #279 from keszybz/pr272-rework
Zbigniew Jędrzejewski-Szmek [Fri, 2 Nov 2018 18:18:34 +0000 (19:18 +0100)] 
Merge pull request #279 from keszybz/pr272-rework

Fix typing in partition() function

6 years agoRemove now-redundant check if partno is None 279/head
Zbigniew Jędrzejewski-Szmek [Fri, 2 Nov 2018 18:04:00 +0000 (19:04 +0100)] 
Remove now-redundant check if partno is None

6 years agotyping: use non-None types for partition()
Zygmunt Krynicki [Wed, 24 Oct 2018 10:04:03 +0000 (12:04 +0200)] 
typing: use non-None types for partition()

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
6 years agoMerge pull request #278 from poettering/qcow2
Zbigniew Jędrzejewski-Szmek [Fri, 2 Nov 2018 17:59:40 +0000 (18:59 +0100)] 
Merge pull request #278 from poettering/qcow2

optionally convert output to qcow2

6 years agomkosi: optionally convert resulting image to qcow2 278/head
Lennart Poettering [Thu, 1 Nov 2018 09:25:55 +0000 (10:25 +0100)] 
mkosi: optionally convert resulting image to qcow2

Fixes: #218
6 years agomkosi: fix checks whether configuration settings are already set
Lennart Poettering [Thu, 1 Nov 2018 09:25:20 +0000 (10:25 +0100)] 
mkosi: fix checks whether configuration settings are already set

6 years agoMerge pull request #277 from lucasdemarchi/tip-fix-symlink
Lennart Poettering [Thu, 1 Nov 2018 09:31:10 +0000 (10:31 +0100)] 
Merge pull request #277 from lucasdemarchi/tip-fix-symlink

Misc fixes

6 years agoFix output dir creation 277/head
Rafael Antognolli [Fri, 20 Jul 2018 20:54:16 +0000 (13:54 -0700)] 
Fix output dir creation

The cache dir is created inside the output dir, so we need to create the
output dir at least before that. Fix the following error:

$ sudo mkosi -d fedora -r 29 -t directory -O bla --default /dev/null

Traceback (most recent call last):
  File "/bin/mkosi", line 3767, in <module>
    main()
  File "/bin/mkosi", line 3757, in main
    build_stuff(args)
  File "/bin/mkosi", line 3573, in build_stuff
    setup_package_cache(args)
  File "/bin/mkosi", line 2412, in setup_package_cache
    d = tempfile.TemporaryDirectory(dir=os.path.dirname(args.output), prefix=".mkosi-")
  File "/usr/lib64/python3.7/tempfile.py", line 788, in __init__
    self.name = mkdtemp(suffix, prefix, dir)
  File "/usr/lib64/python3.7/tempfile.py", line 366, in mkdtemp
    _os.mkdir(file, 0o700)
FileNotFoundError: [Errno 2] No such file or directory: '/home/lucas/p/mkosi/bla/.mkosi-l3oxfchg'

6 years agoFix defaults symlink
Lucas De Marchi [Wed, 31 Oct 2018 23:55:34 +0000 (16:55 -0700)] 
Fix defaults symlink

configs/ got moved to mkosi.files but the symlink was left behind.

6 years agoMerge pull request #276 from poettering/rndseed
Lennart Poettering [Wed, 31 Oct 2018 19:36:15 +0000 (20:36 +0100)] 
Merge pull request #276 from poettering/rndseed

drop random seed in built images, and other fixlets

6 years agomkosi: if/elif simplifications 276/head
Lennart Poettering [Wed, 31 Oct 2018 17:53:14 +0000 (18:53 +0100)] 
mkosi: if/elif simplifications

6 years agomkosi: remove random seed file in images
Lennart Poettering [Wed, 31 Oct 2018 17:48:09 +0000 (18:48 +0100)] 
mkosi: remove random seed file in images

If the random seed is part of the image, then each time it is run would
start with the same pool hence the entropy would be much smaller.

6 years agomkosi: use the usual way to show start/finish of one of the steps for the password...
Lennart Poettering [Wed, 31 Oct 2018 17:39:54 +0000 (18:39 +0100)] 
mkosi: use the usual way to show start/finish of one of the steps for the password setting too

6 years agomkosi: strictly require offline operation from systemctl
Lennart Poettering [Wed, 31 Oct 2018 17:39:06 +0000 (18:39 +0100)] 
mkosi: strictly require offline operation from systemctl

It's very likely systemctl will run in one of the scripts. Let's always
make sure it never even tries to talk to PID, simply as a matter of
robustness.

Fixes: #262
6 years agoMerge pull request #273 from zyga/args-type
Zbigniew Jędrzejewski-Szmek [Thu, 25 Oct 2018 15:18:23 +0000 (17:18 +0200)] 
Merge pull request #273 from zyga/args-type

Begin type-checking parsed command line arguments

6 years agoMerge pull request #264 from lucasdemarchi/tip-arch
Zbigniew Jędrzejewski-Szmek [Thu, 25 Oct 2018 09:55:23 +0000 (11:55 +0200)] 
Merge pull request #264 from lucasdemarchi/tip-arch

Fix archlinux

6 years agoRecursively unmount
Lucas De Marchi [Sat, 6 Oct 2018 01:17:24 +0000 (18:17 -0700)] 
Recursively unmount

We always want to unmount anything left on the root mountpoint. Just
use the --recursive switch from umount.

6 years agoAdd type annotations for esp_partno 273/head
Zygmunt Krynicki [Wed, 24 Oct 2018 11:36:30 +0000 (13:36 +0200)] 
Add type annotations for esp_partno

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
6 years agoAdd type annotations to swap_partno
Zygmunt Krynicki [Wed, 24 Oct 2018 11:35:09 +0000 (13:35 +0200)] 
Add type annotations to swap_partno

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>