make-disk-image: add testMode, copyNixStore & extraConfig params

This commit is contained in:
lassulus 2024-07-21 16:44:48 +02:00
parent 6208b31a73
commit c5e5018a04

View file

@ -5,6 +5,9 @@
, name ? "${nixosConfig.config.networking.hostName}-disko-images" , name ? "${nixosConfig.config.networking.hostName}-disko-images"
, extraPostVM ? nixosConfig.config.disko.extraPostVM , extraPostVM ? nixosConfig.config.disko.extraPostVM
, checked ? false , checked ? false
, copyNixStore ? true
, testMode ? false
, extraConfig ? { }
}: }:
let let
vmTools = pkgs.vmTools.override { vmTools = pkgs.vmTools.override {
@ -15,10 +18,14 @@ let
}; };
cleanedConfig = diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices; cleanedConfig = diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices;
systemToInstall = nixosConfig.extendModules { systemToInstall = nixosConfig.extendModules {
modules = [{ modules = [
disko.devices = lib.mkForce cleanedConfig.disko.devices; extraConfig
boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices; {
}]; disko.testMode = true;
disko.devices = lib.mkForce cleanedConfig.disko.devices;
boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices;
}
];
}; };
dependencies = with pkgs; [ dependencies = with pkgs; [
bash bash
@ -48,6 +55,7 @@ let
rootPaths = [ systemToInstall.config.system.build.toplevel ]; rootPaths = [ systemToInstall.config.system.build.toplevel ];
}; };
partitioner = '' partitioner = ''
set -efux
# running udev, stolen from stage-1.sh # running udev, stolen from stage-1.sh
echo "running udev..." echo "running udev..."
ln -sfn /proc/self/fd /dev/fd ln -sfn /proc/self/fd /dev/fd
@ -63,10 +71,13 @@ let
udevadm trigger --action=add udevadm trigger --action=add
udevadm settle udevadm settle
${lib.optionalString testMode ''
export IN_DISKO_TEST=1
''}
${systemToInstall.config.system.build.diskoScript} ${systemToInstall.config.system.build.diskoScript}
''; '';
installer = '' installer = lib.optionalString copyNixStore ''
# populate nix db, so nixos-install doesn't complain # populate nix db, so nixos-install doesn't complain
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
nix-store --load-db < "${closureInfo}/registration" nix-store --load-db < "${closureInfo}/registration"