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

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

  # Bootloader stuff
  boot.kernelParams = [
    "quiet"
    "splash"
    "rd.systemd.show_status=false"
    "acpi_backlight=native"
    "video=efifb:nobgrt"
    "loglevel=3"
    "rd.udev.log_level=3"
  ];
  boot.kernelPackages = pkgs.linuxPackages_latest;

  boot.loader.systemd-boot = {
    enable = true;
    configurationLimit = 3;
  };
  boot.loader.efi = {
    canTouchEfiVariables = true;
  };

  boot.initrd.systemd.enable = true;
  boot.plymouth = {
    enable = true;
    themePackages = with pkgs; [ catppuccin-plymouth ];
    theme = "catppuccin-macchiato";
    extraConfig = ''
      UseFirmwareBackground=false
    '';
  };

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

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

  # Enable opengl
  hardware.graphics = {
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver
      vaapiVdpau
      libvdpau-va-gl
    ];
  };

  # Bluetooth stuff
  services.blueman.enable = true;
  hardware.bluetooth.enable = true;
  services.pipewire.wireplumber.extraConfig = {
    "monitor.bluez.properties" = {
      "bluez5.enable-sbc-xq" = true;
      "bluez5.enable-msbc" = true;
      "bluez5.enable-hw-volume" = true;
      "bluez5.roles" = [
        "hsp_hs"
        "hsp_ag"
        "hfp_hf"
        "hfp_ag"
      ];
    };
  };

  # Setup hyprland
  services.xserver.enable = true;
  services.xserver.displayManager = {
    gdm.wayland = true;
    lightdm.enable = false;
  };
  programs.hyprland = {
    enable = true;
    xwayland.enable = true;
    portalPackage = pkgs.xdg-desktop-portal-hyprland;
  };

  # TRIM
  services.fstrim.enable = true;

  # TLP
  services.tlp.enable = true;

  # Brillo
  hardware.brillo.enable = true;

  # 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;
      [
        # xdg-desktop-portal-hyprland
        xdg-desktop-portal-gtk
      ]
    );
  };

  programs.steam.enable = true;

  # Enable flakes
  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];
  nix.settings.trusted-users = [
    "root"
    "torjus"
  ];

  nixpkgs.config.allowUnfree = true;
  # Install system-wide packages
  environment.systemPackages = with pkgs; [
    vim
    wget
    curl
    git
  ];

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