# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config
, pkgs
, inputs
, hostname
, username
, ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
    inputs.catppuccin.nixosModules.catppuccin
  ];

  ## Boot
  # Bootloader.
  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/nvme0n1";

  # Use latest kernel.
  boot.kernelPackages = pkgs.linuxPackages_latest;

  ## Network
  networking.hostName = hostname;
  # Enable networking
  networking.networkmanager.enable = true;

  ## Time/Language
  # Set your time zone.
  time.timeZone = "Europe/Berlin";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

  # Configure console keymap
  console.keyMap = "de";

  ## Nix
  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];
  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  ## Global packages
  environment.systemPackages = with pkgs; [
    vim
    wget
    git
    cifs-utils # required for network mounting the NAS
    inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default
    age
  ];

  fonts = {
    enableDefaultPackages = true;
    packages = with pkgs; [
      nerd-fonts.jetbrains-mono
    ];
    fontDir.enable = true;
  };

  catppuccin.enable = true;

  programs.hyprland = {
    enable = true;
    xwayland.enable = true;
  };
  programs.zsh.enable = true;

  programs.steam = {
    enable = true;
    extraCompatPackages = [
      pkgs.proton-ge-bin
    ];
    protontricks = {
      enable = true;
    };
    dedicatedServer.openFirewall = true;
    localNetworkGameTransfers.openFirewall = true;
    remotePlay.openFirewall = true;
  };

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  programs.gnupg.agent = {
    enable = true;
    enableSSHSupport = true;
  };

  ## User config
  # enable auto-login
  services.getty.autologinUser = username;

  users.users.${username} = {
    isNormalUser = true;
    extraGroups = [ "networkmanager" "wheel" ];
    shell = pkgs.zsh;
  };

  ## NAS Mount

  fileSystems."/mnt/nas" = {
    device = "//duke.veltnet/smb-share";
    fsType = "cifs";
    options = [
      "x-systemd.automount"
      "noauto"
      "user,users"
      "uid=1000"
      "gid=100"
      "credentials=/etc/nixos/secrets/nas-share.creds"
    ];
  };

  # required for zsh completion
  environment.pathsToLink = [ "/share/zsh" ];

  environment.sessionVariables.NIXOS_OZONE_WL = "1";

  # List services that you want to enable:

  services.kanata = {
    enable = true;
    #TODO: kanata config
  };

  services.mullvad-vpn.enable = true;
  services.pipewire = {
    alsa.enable = true;
    enable = true;
    wireplumber.enable = true;
  };

  networking.firewall.enable = false;

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "25.11"; # Did you read the comment?
}
