{
  config,
  pkgs,
  lib,
  modulesPath,
  targetSystem,
  ...
}:
let
  installer = pkgs.writeShellApplication {
    name = "installer";
    runtimeInputs = with pkgs; [
      # clevis
      dosfstools
      e2fsprogs
      gawk
      nixos-install-tools
      util-linux
      config.nix.package
    ];
    text = ''
      set -euo pipefail

      ${targetSystem.config.system.build.diskoScript}

      nixos-install --no-channel-copy --no-root-password --option substituters "" --system ${targetSystem.config.system.build.toplevel}
    '';
  };
  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.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_17;
  # boot.zfs.package = pkgs.zfs_unstable;
  boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux;
  boot.kernelParams = [
    "quiet"
    "systemd.unit=getty.target"
  ];
  boot.supportedFilesystems.zfs = true;
  boot.initrd.systemd.enable = true;

  networking.hostId = "04581ecf";

  isoImage.makeEfiBootable = true;
  isoImage.makeUsbBootable = true;
  isoImage.squashfsCompression = "zstd -Xcompression-level 15";

  environment.systemPackages = [
    installer
  ];

  systemd.services."getty@tty1" = {
    overrideStrategy = "asDropin";
    serviceConfig = {
      ExecStart = [
        ""
        installerFailsafe
      ];
      Restart = "no";
      StandardInput = "null";
    };
  };

  # system.stateVersion = lib.mkDefault lib.trivial.release;
  system.stateVersion = "24.11";
}
