1 # Building Images via `systemd-repart` {#sec-image-repart}
3 You can build disk images in NixOS with the `image.repart` option provided by
4 the module [image/repart.nix][]. This module uses `systemd-repart` to build the
5 images and exposes it's entire interface via the `repartConfig` option.
7 [image/repart.nix]: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/image/repart.nix
9 An example of how to build an image:
12 { config, modulesPath, ... }: {
14 imports = [ "${modulesPath}/image/repart.nix" ];
29 storePaths = [ config.system.build.toplevel ];
42 ## Nix Store Partition {#sec-image-repart-store-partition}
44 You can define a partition that only contains the Nix store and then mount it
45 under `/nix/store`. Because the `/nix/store` part of the paths is already
46 determined by the mount point, you have to set `stripNixStorePrefix = true;` so
47 that the prefix is stripped from the paths before copying them into the image.
51 fileSystems."/nix/store".device = "/dev/disk/by-partlabel/nix-store";
53 image.repart.partitions = {
55 storePaths = [ config.system.build.toplevel ];
56 stripNixStorePrefix = true;
58 Type = "linux-generic";
67 ## Appliance Image {#sec-image-repart-appliance}
69 The `image/repart.nix` module can also be used to build self-contained [software
72 [software appliances]: https://en.wikipedia.org/wiki/Software_appliance
74 The generation based update mechanism of NixOS is not suited for appliances.
75 Updates of appliances are usually either performed by replacing the entire
76 image with a new one or by updating partitions via an A/B scheme. See the
77 [Chrome OS update process][chrome-os-update] for an example of how to achieve
78 this. The appliance image built in the following example does not contain a
79 `configuration.nix` and thus you will not be able to call `nixos-rebuild` from
80 this system. Furthermore, it uses a [Unified Kernel Image][unified-kernel-image].
82 [chrome-os-update]: https://chromium.googlesource.com/aosp/platform/system/update_engine/+/HEAD/README.md
83 [unified-kernel-image]: https://uapi-group.org/specifications/specs/unified_kernel_image/
87 pkgs = import <nixpkgs> { };
88 efiArch = pkgs.stdenv.hostPlatform.efiArch;
91 ({ config, lib, pkgs, modulesPath, ... }: {
93 imports = [ "${modulesPath}/image/repart.nix" ];
95 boot.loader.grub.enable = false;
97 fileSystems."/".device = "/dev/disk/by-label/nixos";
104 "/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
105 "${pkgs.systemd}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
107 "/EFI/Linux/${config.system.boot.loader.ukiFile}".source =
108 "${config.system.build.uki}/${config.system.boot.loader.ukiFile}";
113 SizeMinBytes = "96M";
117 storePaths = [ config.system.build.toplevel ];