{ config, pkgs, lib, modulesPath, targetSystem, ... }: let installer = pkgs.writeShellApplication { name = "installer"; runtimeInputs = []; text = '' #!${pkgs.runtimeShell} set -euo pipefail echo "Formatting the disk..." ${pkgs.util-linux}/bin/blkid -o device > /tmp/devices # DISKO_DEVICE_MAIN="$(${pkgs.gum}/bin/gum choose < /tmp/devices)" DISKO_DEVICE_MAIN=/dev/vda export DISKO_DEVICE_MAIN echo "Selected device: $DISKO_DEVICE_MAIN" ${targetSystem.config.system.build.diskoScript} export PATH=${lib.makeBinPath [ # hack for a progress bar # https://nix.dev/manual/nix/2.18/command-ref/nix-build#opt-log-format (pkgs.writeShellScriptBin "nix-env" '' exec ${lib.getExe' config.nix.package "nix-env"} --log-format bar "$@" '') ]}:$PATH echo "Installing NixOS..." ${pkgs.nixos-install}/bin/nixos-install --no-channel-copy --no-root-password --option substituters "" --system ${targetSystem.config.system.build.toplevel} ''; }; # This is a failsafe script that will run if the installer fails to start installerFailsafe = pkgs.writeShellScript "failsafe" '' ${lib.getExe installer} || echo "ERROR: Installation failure!" sleep 3600 ''; in { imports = [ (modulesPath + "/installer/cd-dvd/iso-image.nix") (modulesPath + "/profiles/all-hardware.nix") ]; boot.kernelParams = ["systemd.unit=getty.target"]; isoImage.squashfsCompression = "zstd -Xcompression-level 15"; # xz takes forever # systemd service to start the installer on boot system.stateVersion = "25.05"; systemd.services."getty@tty1" = { overrideStrategy = "asDropin"; serviceConfig = { ExecStart = ["" installerFailsafe]; Restart = "no"; StandardInput = "null"; }; }; }