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

{
  imports = [
    ./hardware-configuration.nix
    ../../system/monitoring.nix
  ];

  # Sops stuff
  sops.defaultSopsFile = ../../secrets/gunter/secrets.yaml;
  sops.age.keyFile = "/var/lib/sops-nix/key.txt";
  sops.age.generateKey = true;
  sops.secrets."gotify_tokens/backup-home" = { };

  # Enable microcode updates
  hardware.enableRedistributableFirmware = true;

  # Bootloader stuff
  boot = {
    # Kernel stuff
    # kernelPackages = pkgs.linuxPackages_xanmod_latest;
    kernelPackages = pkgs.linuxPackages_latest;
    # kernelPackages = lib.warn "Pinned to kernel 6.10 due to nvidia fbdev trouble!" pkgs.linuxPackages_6_10;
    kernelParams = [
      "quiet"
      "splash"
      "rd.systemd.show_status=false"
    ];

    extraModprobeConfig = ''
      options v4l2loopback exclusive_caps=1 card_label="Virtual Camera"
    '';

    # Bootloader stuff
    loader.systemd-boot = {
      enable = true;
      configurationLimit = 10;
    };
    loader.efi = {
      canTouchEfiVariables = true;
    };
    supportedFilesystems = [ "nfs" ];
  };

  # Networking stuff
  networking.hostName = "gunter"; # Define your hostname.
  networking.networkmanager.enable = true;
  networking.nftables.enable = true;
  networking.firewall = {
    enable = true;
  };

  # Set time stuff
  time.timeZone = "Europe/Oslo";

  # Enable graphics
  hardware.graphics = {
    enable = true;
    extraPackages = with pkgs; [
      vaapiVdpau
      nvidia-vaapi-driver
    ];
  };

  # Nvidia stuff
  hardware.nvidia = {
    modesetting.enable = true;
    powerManagement.enable = false;
    powerManagement.finegrained = false;
    open = true;
    nvidiaSettings = false;

    package = config.boot.kernelPackages.nvidiaPackages.latest;
    # package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
    #   version = "560.28.03";
    #   sha256_64bit = "sha256-martv18vngYBJw1IFUCAaYr+uc65KtlHAMdLMdtQJ+Y=";
    #   sha256_aarch64 = lib.fakeHash;
    #   openSha256 = "sha256-asGpqOpU0tIO9QqceA8XRn5L27OiBFuI9RZ1NjSVwaM=";
    #   settingsSha256 = lib.fakeHash;
    #   persistencedSha256 = lib.fakeSha256;
    # };
  };

  # Setup hyprland
  # nixpkgs.overlays = [
  #   (self: super: {
  #     hyprland = super.hyprland.override {
  #       debug = true;
  #     };
  #   })
  # ];
  services.xserver.enable = true;
  services.xserver.videoDrivers = [ "nvidia" ];
  services.xserver.displayManager.gdm.wayland = true;
  services.xserver.displayManager.lightdm.enable = false;
  services.xserver.displayManager.startx.enable = true;
  services.xserver.windowManager.i3.enable = true;
  programs.hyprland = {
    enable = true;
    xwayland.enable = true;
    portalPackage = pkgs.xdg-desktop-portal-hyprland;
  };

  # Setup common XDG env vars
  environment.sessionVariables = rec {
    XDG_CACHE_HOME = "$HOME/.cache";
    XDG_CONFIG_HOME = "$HOME/.config";
    XDG_DATA_HOME = "$HOME/.local/share";
    XDG_STATE_HOME = "$HOME/.local/state";
    XDG_BIN_HOME = "$HOME/.local/bin";
    PATH = [ "${XDG_BIN_HOME}" ];
  };

  # Setup xdg portal
  xdg.portal = {
    enable = true;
    xdgOpenUsePortal = true;
    extraPortals = (
      with pkgs;
      [
        # unstable.xdg-desktop-portal-hyprland
        xdg-desktop-portal-gtk
      ]
    );
  };

  # Enable flakes
  nix.settings = {
    experimental-features = [
      "nix-command"
      "flakes"
    ];
    trusted-users = [
      "root"
      "torjus"
    ];
    substituters = [ "https://cuda-maintainers.cachix.org" ];
    trusted-public-keys = [
      "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
    ];
  };

  nixpkgs.config.allowUnfree = true;
  # Install system-wide packages
  environment.systemPackages = with pkgs; [
    curl
    git
    libnotify
    usbutils
    vim
    wget
    v4l-utils
    nmap
    (lib.mkIf (config.system.name == "gunter") pciutils)

    # X shit
    # xorg.xorgserver
    # xorg.xinit
    # xorg.xf86inputevdev
    # xorg.xf86inputlibinput
    # xorg.xinit
  ];

  # 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 = "23.11"; # Did you read the comment?
}