{ config, pkgs, lib, disko, ... }:

{
  imports = [
    ./hardware.nix
    ./disks.nix
  ];

  boot.extraModulePackages = with config.boot.kernelPackages; [
    v4l2loopback
  ];

  sydnix = {
    filesystemType = "btrfs";
    wifi.enable = true;
    drawing-tablet.enable = true;
    tailscale.enable = true;
    earlyoom.enable = true;
    slippi.enable = true;
    niri.enable = true;
    stylix.enable = true;
    qemu.enable = true;
    flatpak.enable = true;
    # gdm.enable = true;
    openssh.enable = true;
    sydpkgs.overlay.enable = true;
    dank-material-shell.enable = true;

    steam = {
      enable = true;
      impermanenceUsers = ["crumb" "msyds"];
    };

    users.users = [
      "crumb"
      "msyds"
    ];

    impermanence = {
      enable = true;
      directories = [
        # "Warning: Neither /var/lib/nixos nor any of its parents are persisted.
        # This means all users/groups without specified uids/gids will have them
        # reassigned on reboot."
        "/var/lib/nixos"
        # We don't want to have different ssh keys on reboot, because ssh keys
        # are expected to consistently identify machines... I think.  I mostly
        # just think it's annoying to edit ~/.ssh/known_hosts all the time.
        "/etc/ssh"
      ];
      rollback = {
        enable = true;
        device = "/dev/disk/by-partlabel/disk-bootroot-root";
        subvolume = "rootfs";
      };
    };
  };

  # Make pressing the power button suspend the system.
  services.logind.settings.Login = {
    HandlePowerKey = "suspend";
  };

  boot.loader = {
    grub.enable = false;
    systemd-boot.enable = true;
    efi.canTouchEfiVariables = false;
  };

  time.timeZone = "America/Denver";

  i18n.defaultLocale = "en_US.UTF-8";

  console = {
    font = "Lat2-Terminus16";
    useXkbConfig = true; # Use xkb.options in tty.
  };

  hardware.nvidia.open = false;

  services.xserver = {
    # enable = true;
    videoDrivers = [ "nvidia" ];
    xkb = {
      layout = "us";
      options = "ctrl:swapcaps,compose:menu";
    };
  };

  services.libinput = {
    enable = true;
    # Disable mouse acceleration.
    mouse.accelProfile = "flat";
    # Sensitivity.
    mouse.accelSpeed = "-0.5";
  };

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    # Pulseaudio compatibility layer.
    pulse.enable = true;
    wireplumber.enable = true;
  };

  # Ensure pipewire processes get realtime priority.
  security.rtkit.enable = true;

  # services.pulseaudio.package = pkgs.pulseaudioFull;

  # Usually we try to delegate declarations of globally-available packages to
  # separate modules.  These are some exceptional essentials.
  environment.systemPackages = [
    pkgs.neovim
    pkgs.git
    (import ../../scripts/port-tools { inherit pkgs; })
    (import ../../scripts/sydnix-cli { inherit pkgs; })

    # Waypipe provides the equivalent of X11 forwarding for Wayland.  When
    # connecting to a remote, it is required that `waypipe` is on the remote's
    # PATH, thus we include it globally here.
    pkgs.waypipe
    pkgs.cachix
  ];

   security.pki.certificateFiles = [
     ../../public-keys/lolc.at.crt
   ];

  # This option defines the first version of NixOS you have installed on this
  # particular machine, and is used to maintain compatibility with application
  # data (e.g. databases) created on older NixOS versions.
  #
  # Most users should NEVER change this value after the initial install, for any
  # reason, even if you've upgraded your system to a new NixOS release.
  #
  # This value does NOT affect the Nixpkgs version your packages and OS are
  # pulled from, so changing it will NOT upgrade your system - see
  # https://nixos.org/manual/nixos/stable/#sec-upgrading for how to actually do
  # that.
  #
  # This value being lower than the current NixOS release does NOT mean your
  # system is out of date, out of support, or vulnerable.
  #
  # Do NOT change this value unless you have manually inspected all the changes
  # it would make to your configuration, and migrated your data accordingly.
  #
  # For more information, see `man configuration.nix` or
  # https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
  system.stateVersion = "24.05"; # Did you read the comment?
}
