{ config, lib, pkgs, ... }: { sdImage.expandOnBoot = false; boot.postBootCommands = '' # On the first boot do some maintenance tasks if [ -f /mnt/image/nix-path-registration ]; then set -euo pipefail set -x # Figure out device names for the boot device and root filesystem. rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /mnt/image) bootDevice=$(lsblk -npo PKNAME $rootPart) partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}') # Resize the root partition and the filesystem to fit the disk echo ",+," | sfdisk -N$partNum --no-reread $bootDevice ${pkgs.parted}/bin/partprobe ${pkgs.e2fsprogs}/bin/resize2fs $rootPart # Register the contents of the initial Nix store ${config.nix.package.out}/bin/nix-store --load-db < /mnt/image/nix-path-registration # nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag. touch /etc/NIXOS ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system # Prevents this from running on later boots. rm -f /mnt/image/nix-path-registration fi ''; }