#cloud-config
autoinstall:
  version: 1

  # Locale and keyboard
  locale: en_US.UTF-8
  keyboard:
    layout: us

  # Network configuration - DHCP on all interfaces
  network:
    network:
      version: 2
      ethernets:
        id0:
          match:
            driver: "*"
          dhcp4: true

  # Storage - use entire disk
  storage:
    layout:
      name: direct

  # Identity - create ecouser
  identity:
    hostname: ecoos
    username: ecouser
    # Password: ecouser (hashed with mkpasswd -m sha-512)
    password: "$6$rounds=4096$randomsalt$n8Y5TqMKJZ5kM3LN0Y5fZ5Y5kM3LN0Y5fZ5Y5kM3LN0Y5fZ5Y5kM3LN0Y5fZ5Y5kM3LN0Y5fZ5Y5kM3LN0Y5f"

  # SSH
  ssh:
    install-server: true
    allow-pw: true

  # Additional packages
  packages:
    - sway
    - seatd
    - pipewire
    - pipewire-pulse
    - foot
    - curl
    - git
    - htop

  # Late commands - run after installation
  late-commands:
    # Add ecouser to required groups
    - curtin in-target -- usermod -aG sudo,video,render,input,seat ecouser

    # Enable passwordless sudo for ecouser
    - echo "ecouser ALL=(ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/ecouser
    - chmod 440 /target/etc/sudoers.d/ecouser

    # Enable seatd
    - curtin in-target -- systemctl enable seatd

    # Install Deno
    - curtin in-target -- curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/opt/eco sh

    # Copy eco-daemon files (assumes they're on the ISO)
    - cp -r /cdrom/eco/* /target/opt/eco/

    # Enable eco-daemon service
    - curtin in-target -- systemctl enable eco-daemon

    # Chromium is already installed in the ISO via live-build hook

  # Reboot after installation
  shutdown: reboot
