# 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,
  ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
    ./disk.nix
    ./sddm.nix
    inputs.home-manager.nixosModules.default
  ];

  hardware.graphics = {
    enable = true;
  };

  nix.settings.experimental-features = ["nix-command" "flakes"];

  # Nvidia set-up
  services.xserver.videoDrivers = ["nvidia"];

  hardware.nvidia = {
    modesetting.enable = true;
    powerManagement.enable = false;
    powerManagement.finegrained = false;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
  };

  # Enable the X11
  services.xserver.enable = true;
  xdg.portal = {
    enable = true;
    extraPortals = [pkgs.xdg-desktop-portal-gtk];
    configPackages = with pkgs; [
      xdg-desktop-portal-gtk
    ];
  };

  # Bootloader.
  boot = {
    kernelPackages = pkgs.linuxPackages_6_6;

    loader.grub = {
      enable = true;
      device = "/dev/sda";
      useOSProber = true;
      milk-theme.enable = true;
      gfxmodeBios = "1680x1050";
      gfxpayloadBios = "keep";
    };
  };

  networking = {
    hostName = "benag";
    networkmanager.enable = true;
  };

  time.timeZone = "Europe/Prague";

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

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

  services = {
    printing.enable = true;
    printing.browsing = true;
    printing.defaultShared = true;
    printing.drivers = [pkgs.hplip pkgs.gutenprint];
    pulseaudio.enable = false;

    avahi = {
      enable = true;
      nssmdns4 = true;
      openFirewall = true;
    };

    pipewire = {
      enable = true;
      pulse.enable = true;

      alsa = {
        enable = true;
        support32Bit = true;
      };
    };

    xserver = {
      windowManager.bspwm.enable = true;

      xkb = {
        layout = "cz";
        variant = "";
        options = "caps:escape";
      };
    };
  };

  console.keyMap = "cz-lat2";

  security.rtkit.enable = true;

  users.defaultUserShell = pkgs.zsh;
  programs.zsh.enable = true;

  users.users.benag = {
    isNormalUser = true;
    description = "Ben Ag";
    extraGroups = ["networkmanager" "wheel"];
  };

  home-manager = {
    extraSpecialArgs = {inherit inputs;};
  };

  programs.firefox.enable = true;
  programs.dconf.enable = true;
  programs.steam.enable = true;
  programs.nix-ld.enable = true;

  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.nvidia.acceptLicense = true;

  environment.systemPackages = with pkgs; [
    bspwm
    feh
    mumble
    sxhkd
    polybar
    kitty
    home-manager
    git
    go
    kdePackages.dolphin
    openfortivpn
    man-pages
    man-pages-posix
  ];

  fonts.packages = with pkgs; [
    nerd-fonts.fira-code
  ];

  # 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;
  # };

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;
  system.activationScripts.cleanBackups = ''
    echo "Removing.backup_nix files..."
    find /home/benag -type f -name "*.backup_nix" -delete
  '';
  system.stateVersion = "25.05";
}
