# Live USB ISO configuration for recovery and installation
{ pkgs, modulesPath, ... }:

{
  imports = [
    # Use minimal installation CD as base
    (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
  ];

  # Use roles structure for consistent configuration
  roles = {
    audio.enable = true;
    bluetooth.enable = true;
    desktop = {
      enable = true;
      kde = true;
      x11 = true;
      wayland = true;
      sddm = true;
    };
  };

  # Allow unfree packages for broader hardware support
  nixpkgs.config.allowUnfree = true;

  # Essential packages for system recovery and installation
  environment.systemPackages = with pkgs; [
    # Text editors
    neovim
    nano
    
    # System tools
    git
    curl
    wget
    htop
    tree
    lsof
    strace
    
    # Filesystem tools
    btrfs-progs
    e2fsprogs
    xfsprogs
    ntfs3g
    dosfstools
    
    # Network tools
    networkmanager
    wirelesstools
    
    # Hardware tools
    pciutils
    usbutils
    smartmontools
    
    # Archive tools
    unzip
    p7zip
    
    # Development tools (for quick fixes)
    gcc
    binutils
  ];

  # Enable NetworkManager for easy wifi setup
  networking.networkmanager.enable = true;
  # Disable wireless networking (conflicts with NetworkManager)
  networking.wireless.enable = false;
  
  # Enable SSH daemon for remote access
  services.openssh = {
    enable = true;
    settings = {
      PermitRootLogin = "yes";
      PasswordAuthentication = true;
    };
  };

  # ISO customization
  isoImage = {
    volumeID = "NIXOS-LIVE";
  };

  # Enable some useful services
  services.udisks2.enable = true; # For mounting USB drives

  # Hardware support
  hardware.enableAllFirmware = true;
  hardware.enableRedistributableFirmware = true;
}
