{ config, pkgs, lib, nixos-hardware, ... }:

{
  imports = [
    # nixos-hardware.nixosModules.raspberry-pi-4
    ../../common/nixos/openssh.nix
  ];

  nix = {
    settings = {
      experimental-features = [ "nix-command" "flakes" ];
      trusted-users = [ "root" "@wheel" ];
    };
  };

  nixpkgs = {

    # Configure your nixpkgs instance
    config = {
      # Disable if you don't want unfree packages
      allowUnfree = true;
    };
  };

  boot = {
    initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
    # ttyAMA0 is the serial console broken out to the GPIO
    kernelParams = [
      "8250.nr_uarts=1"
      "console=ttyAMA0,115200"
      "console=tty1"
    ];
    loader = {
      grub.enable = false;
      raspberryPi = {
        version = 4;
      };
    };
  };

  # # https://nixos.wiki/wiki/NixOS_on_ARM/Raspberry_Pi_4
  # hardware = {
  #   raspberry-pi."4".apply-overlays-dtmerge.enable = true;
  #   deviceTree = {
  #     enable = true;
  #     filter = "*rpi-4-*.dtb";
  #   };
  # };

  console.enable = false;

  environment.systemPackages = with pkgs; [
    libraspberrypi
    raspberrypi-eeprom
    ssh-to-age
    vim
    git
    curl
    wget
    dnsutils
  ];

  networking = {
    hostName = "nixos";
    wireless.enable = false;
    networkmanager.enable = false;
  };

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.truxnell = {
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
    packages = with pkgs; [
    ];
    openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMZS9J1ydflZ4iJdJgO8+vnN8nNSlEwyn9tbWU9OcysW truxnell@home"
    ];
  };

  # Free up to 1GiB whenever there is less than 100MiB left.
  nix.extraOptions = ''
    min-free = ${toString (100 * 1024 * 1024)}
    max-free = ${toString (1024 * 1024 * 1024)}
  '';
  nixpkgs.hostPlatform = "aarch64-linux";

  system.stateVersion = "23.11";

}
