{ config, lib, pkgs, inputs, ... }:
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ../lib/common.nix
      inputs.lix.nixosModules.default
      # inputs.nixos-hardware.nixosModules.gpd-win-mini-2024
    ];

  boot.binfmt.emulatedSystems = [
    "aarch64-linux" # This adds support for deploying to Raspberry Pi 4
    "armv7l-linux" # This adds support for deploying to Raspberry Pi 2
  ];
  services.xserver.xkb = {
    layout = "us";
    variant = "";
  };

  boot.plymouth.enable = true;

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  services.fstrim.enable = true;

  networking.hostName = "winmini"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Set your time zone.
  time.timeZone = "Europe/Copenhagen";

  networking.networkmanager.enable = true;

  services.colord.enable = true;

  # Select internationalisation properties.
  i18n.defaultLocale = "da_DK.UTF-8";
  
  security.rtkit.enable = true;
  security.pam.loginLimits = [
    {
      domain = "*";
      item = "memlock";
      type = "hard";
      value = "unlimited";
    }
    {
      domain = "*";
      item = "memlock";
      type = "soft";
      value = "unlimited";
    }
  ];
  services.pipewire = {
    #config.pipewire."default.clock.rate" = 44100; # might be moved to a file per https://nixos.org/manual/nixos/stable/release-notes.html#sec-release-23.05-migration-pipewire
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };
  security.polkit.extraConfig = ''
    /* deny steam doing weird shit */
    polkit.addRule(function(action, subject) {
      if (action.id === "org.freedesktop.NetworkManager.settings.modify.system") {
        var name = polkit.spawn(["cat", "/proc/" + subject.pid + "/comm"]);
        if (name.includes("steam")) {
          polkit.log("ignoring steam NM prompt");
          return polkit.Result.NO;
        }
      }
    });
  '';

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.videoDrivers = [ "amdgpu" "modesetting" ];
  services.desktopManager.cosmic.enable = true;
  services.desktopManager.cosmic.xwayland.enable = true;
  services.desktopManager.plasma6.enable = true;
  services.desktopManager.plasma6.enableQt5Integration = false;
  services.displayManager.sddm.wayland.enable = true;
  services.displayManager.sddm.enable = true;

  services.fwupd.enable = true;

  services.printing = {
    enable = true;
    drivers = with pkgs; [ hplip ];
  };
  services.pulseaudio.enable = false;
  hardware.bluetooth.enable = true;
  hardware.openrazer = {
    enable = true;
    users = [ "steffen" ];
  };

  programs.dconf.enable = true;
  services.gvfs.enable = true;

  services.guix = {
    enable = false;
    nrBuildUsers = 8;
  };

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.steffen = {
    isNormalUser = true;
    shell = pkgs.fish;
    extraGroups = [ 
      "wheel" 
      "docker"
      "kvm"
      "libvirtd"
      "podman"
      "plugdev"
      "input"
      "cdrom"
    ];
  };

  programs.zsh.enable = true;
  programs.fish.enable = true;

  programs.evince.enable = lib.mkForce false;

  services.udev.packages = [
    pkgs.unstable.wooting-udev-rules
  ];

  environment.systemPackages = with pkgs; [
    btrfs-progs
    #nilfs-utils
    fuse
    ntfs3g
    wireguard-tools
    htop
    gparted
    pkgs.gnome-disk-utility
    kdePackages.plasma-disks
    kdePackages.discover
    polychromatic

    docker-client
    docker-buildx
    clinfo
    unstable.wootility
    smartmontools

    rocmPackages.rocminfo
    rocmPackages.hipcc
    rocmPackages.rocm-smi

    # themes
    papirus-icon-theme
    kdePackages.qtstyleplugin-kvantum
    #kdePackages.konqueror
  ] ++ (with config.boot.kernelPackages; [
    systemtap
    perf
  ]);

  environment.plasma6.excludePackages = with pkgs.kdePackages; [
    spectacle
    elisa
    plasma-browser-integration
    kate
    khelpcenter
    krdp
    baloo-widgets
  ];

  programs.nix-ld = {
    enable = true;
    libraries = with pkgs;
      [
        zlib
        zstd
        stdenv.cc.cc
        stdenv.cc.cc.lib
        udev
        dbus
        mesa
        libglvnd
        curl
        openssl
        attr
        libssh
        bzip2
        libxml2
        acl
        libsodium
        util-linux
        xz
        systemd
      ];
  };

  programs.partition-manager.enable = true;

  environment.sessionVariables = {
     XDG_CACHE_HOME  = "\${HOME}/.cache";
     XDG_CONFIG_HOME = "\${HOME}/.config";
     XDG_BIN_HOME    = "\${HOME}/.local/bin";
     XDG_DATA_HOME   = "\${HOME}/.local/share";
     XDG_DATA_DIRS   = ["/var/lib/flatpak/exports/share" "\$HOME/.local/share/flatpak/exports/share"];
     MOZ_ENABLE_WAYLAND = "1";
  #   # Steam needs this to find Proton-GE
  #   STEAM_EXTRA_COMPAT_TOOLS_PATHS = "\${HOME}/.steam/root/compatibilitytools.d";
  #   # note: this doesn't replace PATH, it just adds this to it
  #   PATH = [ 
  #     "\${XDG_BIN_HOME}"
  #   ];
  };

  fonts.packages = with pkgs; [
    terminus_font
    terminus_font_ttf
    #vollkorn
  ];
  fonts.fontDir.enable = true;

  networking.firewall.allowedTCPPorts = [
    3389
  ];

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

  virtualisation.docker.enable = true;
  virtualisation.podman = {
    enable = true;
    defaultNetwork.settings.dns_enabled = true;
  };

  virtualisation.libvirtd.enable = true;
  programs.virt-manager.enable = true;

  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true;
  };
  programs.cdemu.enable = true;
  programs.gamemode.enable = true;
  services.joycond.enable = true;

  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.allowBroken = true;

  networking.firewall.enable = true;
  services.flatpak.enable = true;

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

}
