Commit graph

58 commits

Author SHA1 Message Date
Robert Rose
0134a1d442 nixos/repart: update zeekstd command 2025-05-29 19:27:22 +02:00
Arian van Putten
871526be1f
nixos/image/repart: Use own assertions / warnings. (#406940) 2025-05-15 19:14:53 +02:00
phaer
8a2195e94e repart: fix whitespace in option descriptions
I mistakenly added extra whitespace in
https://github.com/NixOS/nixpkgs/pull/401872 which negatively affects
aesthetics of our documentation.

Thought it was part of nixfmt-rfc-styles output, but can't reproduce.
Might have had configured the wrong nixfmt.
2025-05-14 09:32:18 +02:00
Will Fancher
26ccfb7a8c nixos/image/repart: Use own assertions / warnings.
It was easy to accidentally trigger infinite recursion if you depended
on `toplevel` in any way before. For instance, if you used
`CopyBlocks` with an image containing `toplevel`. This was because
`toplevel`'s assertion / warning logic has to be evaluated, but that
means evaluating `image.repart`'s assertions / warnings, which
requires evaluating the `repartConfig` attrsets to check for malformed
`Label`s. That causes the module system to type check *all*
`repartConfig` keys, even though most of them aren't used in the
assertions / warnings. So evaluating `system.build.image` evaluates
`repartConfig.CopyBlocks`, which evaluates `toplevel`, which evaluates
assertions / warnings, which evaluates `repartConfig.CopyBlocks` to
type check it. Infinite loop.

Even ignoring this recursion problem, it's still better for the repart
module to have its own assertions / warnings options. You don't have
to use `toplevel` in a repart image, so its assertions / warnings
would have been ignored in that case anyway. This way they're *always*
checked when you build an image.
2025-05-14 01:24:43 -04:00
phaer
9e6e5152ba image/repart: repart.imageFile(BaseName) -> image.baseName, etc
Replace image-specific options for file name (and basename) with
unified options for basename and extension in order to increase
compatibility with nixos-rebuild build-image
2025-04-26 10:55:23 +02:00
phaer
1df1c8828d image/repart: run nixfmt 2025-04-25 22:03:46 +02:00
phaer
0a8b014f67 image/file-options: use defaultText 2025-04-25 22:03:46 +02:00
jopejoe1
e6d927fcfd
cloudstack: add to image/images (#398556) 2025-04-24 19:03:53 +02:00
Nico Felbinger
e0d1b49a46
chore: move meta option to top level in many modules 2025-04-19 18:27:48 +02:00
phaer
d7e76ed0a2 cloudstack: add to image/images
This was an oversight in https://github.com/NixOS/nixpkgs/pull/347275,
so it's currently missing from the variants listed in nixos-rebuild build-image
2025-04-14 14:03:58 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Alexander Foremny
5c28518c4b nixos/modules/image: fix error message
When a module is not found, it did not show the intended error message
`The module ... does not exist`, but rather `path ... does not exist`.
2025-03-19 17:29:28 +00:00
nikstur
16c4ead8d7
zeekstd: init at 0.2.2 (#387636) 2025-03-16 19:17:30 +01:00
Robert Rose
119b75c310 nixos/repart: add zstd-seekable compression algorithm
The seekable format splits compressed data into a series of independent
frames, each of which can be decompressed individually. This allows to
distribute images in smaller chunks and allows image downloads to be
paused and resumed later from the same point.

Seekable archives as a whole can be decompressed with any regular zstd
decompressor. However, partial decompression requires to know the
starting position of the desired frame, which can be extracted from a
skippable frame (aka seektable) that is appended to the compressed data.
2025-03-16 18:32:56 +01:00
Florent Charpentier
631bed6ed9 nixos/systemd-repart: add support for repeating settings
fix https://github.com/NixOS/nixpkgs/issues/389478
2025-03-14 19:43:28 +01:00
Peder Bergebakken Sundt
527be14321 nixos/doc: convert links to manpages 2025-02-21 16:31:09 +01:00
Arian van Putten
098d858f3c
nixos/image/images: fix sd-card image on aarch64 (#372783) 2025-02-17 15:04:27 +01:00
nikstur
8a12cae321 nixos/repart-image: support swap 2025-02-01 18:36:51 +01:00
nikstur
c613b0e446 nixos/repart-image: fix btrfs images 2025-02-01 17:58:01 +01:00
DavHau
6e6be76601 nixos/image.modules: siplify type for better UX
Usage before:

```
image.modules.my-format = [
  (
    { config, pkgs, ... }:
    {
      imports = [ ./my-other-module.nix ];
      foo = "bar";
    };
  )
]
```

Usage after:

```
image.modules.my-format = { config, pkgs, ... }: {
  imports = [ ./my-other-module.nix ];
  foo = "bar";
};
```

If the user wants to pass a list of modules only:
```
image.modules.my-format.imports = [
  ./module1.nix
  ./module2.nix
]
```

cc @phaer @zimbatm
2025-01-13 18:57:14 +07:00
phaer
54632790fb nixos/image/images: fix sd-card image on aarch64
by using qemuArch, not linuxArch. The former is "aarch64",
while the later is "arm64" on such machines.
2025-01-11 00:23:10 +01:00
Thiago Kenji Okada
6e6188af7b
image/images: Adapt remaining images to system.build.image & normalized filenames, (#359345) 2025-01-05 20:28:23 +00:00
WilliButz
685d9fe348
nixos/repart-verity-store: use mkDefault for partition types
This makes it a bit easier to switch between using the default usr
veritysetup generator or the nix-store veritysetup generator.
2024-12-17 17:12:42 +01:00
WilliButz
8404744352
nixos/repart-verity-store: set supportedFilesystems, drop fileSystems entry from test
The `/usr` entry in `fileSystems` is superfluous and currently
interferes with the systemd generator. Dropping the `fileSystem` entry
requires making the appropriate module explicitly available in initrd.
2024-12-17 17:12:42 +01:00
phaer
e3347c19b3 image/images: Add remaining image modules
to achieve feature parity with nixos-generators
2024-12-16 15:35:22 +01:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
phaer
c78003c4e0 image/images: Add image modules defined in virtualisation/ 2024-11-29 17:13:54 +01:00
phaer
08b9155e20 image/images: init
A new NixOS module that adds two new options to `system.build`:

- imageModules: An attrset mapping image variant names to a list of nixos
  modules to use when building such images.

- images: An attrset mapping image variant names to a nixos instance
  based on the current config plus variant-specific modules (see
  `system.build.imageModules` above.
2024-11-26 19:04:53 +01:00
phaer
148ba06717 image/file-options: init 2024-11-26 19:04:53 +01:00
Arian van Putten
1b592cdeb4 nixos/image/repart: unsafeDiscardReferences.out = true
Lets set this in the repart module instead of the verity module
2024-10-10 11:48:36 +02:00
WilliButz
93c61c1e58
nixos/repart-verity-store: include original roothashes in repart-output.json 2024-09-30 22:45:05 +02:00
WilliButz
3f1f20b2a7
nixos/repart-image: pass partition attrs to builder instead of JSON file
Having access to the original Nix partition definitions in the builder
should make it a bit easier to manipulate them and still provide access
to the manipulated results.
2024-09-30 20:10:51 +02:00
WilliButz
942588c686
nixos/repart-verity-store: init
This module provides some abstraction for a multi-stage build to create
a dm-verity protected NixOS repart image.

The opinionated approach realized by this module is to first create an
immutable, verity-protected nix store partition, then embed the root
hash of the corresponding verity hash partition in a UKI, that is then
injected into the ESP of the resulting image.
The UKI can then precisely identify the corresponding data from which
the entire system is bootstrapped.

The module comes with a script that checks the UKI used in the final
image corresponds to the intermediate image created in the first step.
This is necessary to notice incompatible substitutions of
non-reproducible store paths, for example when working with distributed
builds, or when offline-signing the UKI.
2024-09-20 17:35:49 +02:00
WilliButz
0864b38144
nixos/repart-image: fix amend script
Calling ruff directly on files was deprecated in favor of
`ruff check`. Since #322953 usage without the subcommand is no longer
possible.
2024-07-10 11:40:40 +02:00
Jared Baur
7aff15e8c4
nixos/systemd-repart: respect NIX_BUILD_CORES for image compression 2024-06-13 21:11:40 -07:00
Daniel Barter
d7a9d49c42 repart-image: removing unshare (and util-linux dep) form systemd-repart invocation
..
2024-06-03 17:48:27 -07:00
stuebinm
6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
nikstur
80cafa6a29
Merge pull request #302590 from nikstur/repart-image-label-length
nixos/image/repart: assert maximum label length
2024-04-08 18:48:53 +02:00
nikstur
ad19cee09c nixos/image/repart: assert maximum label length
The maximum label length is specified by UEFI and enforced/asserted by
systemd-repart. This lets evaluation fail already and give the user
some more information about what's wrong.

Also warn when the suggested label length is exceeded. This serves as a
safety mechanism for using systemd-sysupdate style A/B updates where the
version number is encoded in the label and might not be incrementable
when the maximum label size is reached.
2024-04-08 16:42:25 +02:00
nikstur
b9fe4b1e26 nixos/repart-image: supply explicit --architecture to repart
This enables cross-compiling images.
2024-04-04 17:38:08 +02:00
WilliButz
d9264d0568
nixos/repart-image: add myself as maintainer 2024-03-21 11:37:43 +01:00
WilliButz
5282cdd926
nixos/repart-image: add internal option to expose finalPartitions 2024-03-21 11:37:43 +01:00
WilliButz
d7ef2defda
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:

* Previously the attribute set `compression` needed to be fully
  populated, including `algorithm` and `level` because
  `compression.enable` was evaluated by bash, after being interpolated
  as strings into the `buildCommand`. Now it's sufficient to pass
  `compression.enable = false` to the builder, e.g. in `overrideAttrs`,
  to disable the compression.
* Using mkDerivation allows for much more customization than the
  previously used `runCommand`, making use of phases and pre/post hooks.
  This is especially helpful for building multiple images from the same
  system configuration, e.g. to build an image `Y` based on a partially
  built raw image `X`,  by injecting a UKI that depends on `X` into a
  defered ESP.
* Before this change it was non-trivial to conduct further manipulations
  on the amended repart definitions. Now, the definitions that
  systemd-repart uses to build the image can be easily manipulated in
  `postPatch` or `preBuild`.

Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-21 11:37:43 +01:00
WilliButz
82ef47d3b7
nixos/repart-image: add options to specify mkfs parameters
This new option makes it easier to specify extra mkfs parameters for the
systemd-repart builder.

See https://github.com/systemd/systemd/blob/v255/docs/ENVIRONMENT.md?plain=1#L575-L577
2024-03-07 22:50:56 +01:00
WilliButz
f88148f05e
nixos/repart-image: improve overridability, use structuredAttrs
Parameters passed to systemd-repart are now passed to the build script
via environment variable, which is defined as a list of strings in
combination with `__structuredAttrs = true`. This should make it easier
to customize the image build using `overrideAttrs`.

Both the script used to amend the repart definitions and the amended
definitions are now available via passthru.
2024-03-07 18:27:11 +01:00
Jared Baur
4e139026b5
nixos/repart: add option for configuring sector size
This option is helpful for situations when the target host disk's sector
size differs from that of the build host.
2024-01-27 17:19:32 -08:00
nikstur
a34af9a955 image/repart: add version and compression options
The version option is needed if you want to implement partition &
systemd-boot based A/B booting where the version information is encoded
in the files on the ESP. See systemd-sysupate docs for more details on
this:
https://www.freedesktop.org/software/systemd/man/latest/sysupdate.d.html

Note, however, that this is not *only* useful for systemd-sysupdate but
also for other similar updating tools/mechanisms.
2024-01-19 14:43:29 +01:00
Jared Baur
f58c5e7154
image/repart: build image with buildPackages
Since the repart image is built on the build platform, use
`buildPackages` to construct the image. This allows for systemd-repart
images for cross-compiled nixos configurations to work properly.
2023-12-21 15:11:13 -08:00
nikstur
14152f80bb nixos/image: fix layout of option examples in repart builder 2023-10-31 11:27:57 +01:00
nikstur
84722633b7 nixos/image: move docs into manual 2023-10-31 11:27:56 +01:00