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

{
  # Bootloader
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  # for testing only, not for building
  boot.binfmt.addEmulatedSystemsToNixSandbox = false;
  boot.binfmt.emulatedSystems = [
    "aarch64-linux"
    "armv7l-linux"
    "riscv64-linux"
  ];
  #nix.settings.system = "x86_64-linux";
  #nix.settings.extra-platforms = [ "i686-linux" ];

  boot.kernel.sysctl."vm.swappiness" = lib.mkDefault 10; # 0-100, commonly 60
  boot.kernelModules = [ "xhci_pci" ]; # add driver to stage-1 to make the usb dock not prevent boot - https://github.com/NixOS/nixpkgs/issues/171625#issuecomment-2068283656

  services.displayManager.autoLogin.enable = true;
  services.displayManager.autoLogin.user = "pbsds";
  # tmp: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229
  systemd.services."getty@tty1".enable = false;
  systemd.services."autovt@tty1".enable = false;

  #boot.kernelPackages = pkgs.linuxPackages_latest;
  #hardware.nvidia.modesetting.enable = false; # makes atom behave, but mpv refuses to start
  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;

  # The open source driver does not support Pascal GPUs (1080)
  # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/pascal/default.nix
  hardware.nvidia.open = false;

  # PRIME: (lspci)
  #hardware.nvidia.prime.intelBusId  = "PCI:0:02:0";
  #hardware.nvidia.prime.nvidiaBusId = "PCI:1:00:0";

  imports = [
    ./hardware-configuration.nix
    ../../../profiles/sshd.nix
    ../../../profiles/no-suspend.nix
    #../../../profiles/oci/podman.nix
    ../../../profiles/oci/docker.nix
    ../../../profiles/oci/distrobox.nix

    ../../../users/pbsds
    ../../../users/pbsds/syncthing.nix

    ../../../profiles/mounts/freon-nfs.nix
    ../../../profiles/mounts/reidun-nfs.nix
    /* ../../../profiles/mounts/meconium-nfs.nix */

    ../../../profiles/shell.nix

    ../../../profiles/desktop
    ../../../profiles/desktop/gnome # configures gdm
    #../../../profiles/desktop/sound/alsa.nix
    #../../../profiles/desktop/sound/pulseaudio.nix
    ../../../profiles/desktop/sound/pipewire.nix

    ../../../profiles/desktop/steam.nix
    #../../../profiles/desktop/xboxdrv.nix # TODO: try out
    ../../../profiles/desktop/lutris.nix
    ../../../profiles/desktop/flatpak.nix

    ../../../profiles/known-hosts.nix
    #../../../profiles/domeneshop-dyndns.nix # handled by noximilien
  ];

  environment.systemPackages = with pkgs; [
    krita
  ];

  networking.firewall.allowedTCPPorts = [ 57621 ]; # spotify local discovery

  hardware.bluetooth.enable = true;

  environment.systemPackages = [
    pkgs.pbsds.v4l2-play
    /* pkgs.librealsense-gui */
  ];

  # Networking
  /**/
  networking.networkmanager.enable = true;
  #networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  networking.interfaces.enp3s0.wakeOnLan.enable = true;
  networking.interfaces.enp3s0.ipv4.addresses = [
    { address = "192.168.1.7"; prefixLength = 24; }
  ];
  networking.defaultGateway.address = "192.168.1.254";
  networking.defaultGateway.interface = "enp3s0";
  networking.nameservers = [
    "192.168.1.254"
    "8.8.8.8"
    "1.1.1.1"
  ];
  #networking.useDHCP = true;
  /** /
  systemd.network.enable = true;
  systemd.network.networks."50-static" = {
    matchConfig.Name = "enp3s0";
    address = [ "192.168.1.7/24" ];
    gateway = [ "192.168.1.254" ];
    dns = [ "192.168.1.254" "8.8.8.8" "1.1.1.1" ];
    domains = [ config.networking.domain ]; # set by flake
    networkConfig.IPv6AcceptRA = false;
    linkConfig.RequiredForOnline = "routable"; # dependency for network-online.target
  };
  /** /
  systemd.network.networks."51-dhcp" = {
    matchConfig.Name = "enp3s0";
    networkConfig.DHCP = "yes";
    networkConfig.IPv6AcceptRA = true;
    linkConfig.RequiredForOnline = "no"; # not always connected and not required to be online
  };
  /**/
  #TODO: avahi? resolved? https://git.pvv.ntnu.no/Drift/pvv-nixos-config/src/main/base.nix#L15-L18

  # TODO: remove? Move?
  programs.dconf.enable = true;

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;
}
