···
54
+
label ? if onlyNixStore then "nix-store" else "nixos"
, # The initial NixOS configuration file to be copied to
# /etc/nixos/configuration.nix.
···
, # Shell code executed after the VM has finished.
63
+
, # Copy the contents of the Nix store to the root of the image and
64
+
# skip further setup. Incompatible with `contents`,
65
+
# `installBootLoader` and `configFile`.
66
+
onlyNixStore ? false
, name ? "nixos-disk-image"
···
(attrs: ((attrs.user or null) == null)
== ((attrs.group or null) == null))
91
+
assert onlyNixStore -> contents == [] && configFile == null && !installBootLoader;
···
echo "copying staging root to image..."
348
-
cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* / ||
354
+
cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} \
357
+
$root${optionalString onlyNixStore builtins.storeDir}/* / ||
(echo >&2 "ERROR: cptofs failed. diskSize might be too small for closure."; exit 1)
351
-
in pkgs.vmTools.runInLinuxVM (
352
-
pkgs.runCommand name
353
-
{ preVM = prepareImage;
361
+
moveOrConvertImage = ''
362
+
${if format == "raw" then ''
363
+
mv $diskImage $out/${filename}
365
+
${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} ${compress} $diskImage $out/${filename}
367
+
diskImage=$out/${filename}
370
+
buildImage = pkgs.vmTools.runInLinuxVM (
371
+
pkgs.runCommand name {
372
+
preVM = prepareImage;
buildInputs = with pkgs; [ util-linux e2fsprogs dosfstools ];
356
-
${if format == "raw" then ''
357
-
mv $diskImage $out/${filename}
359
-
${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} ${compress} $diskImage $out/${filename}
361
-
diskImage=$out/${filename}
374
+
postVM = moveOrConvertImage + postVM;
export PATH=${binPath}:$PATH
rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"}
···
tune2fs -T now -c 0 -i 0 $rootDisk
440
+
if onlyNixStore then
441
+
pkgs.runCommand name {}
442
+
(prepareImage + moveOrConvertImage + postVM)