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

with lib;

{
  imports = with flake.nixosModules.systemProfiles; [
    nfsroot
  ];

  config = {
    nixpkgs = {
      system = "x86_64-linux";
      config = {
        allowUnfree = true;
      };
    };

    boot = {
      initrd = {
        availableKernelModules = [ "nvme" "ahci" "xhci_pci" "usbhid" "sd_mod" "sr_mod" ];
        kernelModules = [ "igb" ];
      };
      kernelModules = [ "kvm-amd" ];
      extraModulePackages = [ ];

      plymouth.enable = true;

      tmpOnTmpfs = true;
    };

    hardware = {
      enableRedistributableFirmware = true;
      cpu.amd.updateMicrocode = config.hardware.enableRedistributableFirmware;

      nvidia = {
        modesetting.enable = true;
        powerManagement.enable = true;
      };

      opengl.enable = true;
    };

    environment.etc."machine-id".text = "f457b21333f1491e916521151ff5d468";

    networking = {
      hostId = "f457b213";

      domain = "asgard.yggdrasil";
      search = [ "asgard.yggdrasil" "yggdrasil" ];

      hosts = {
        "127.0.0.1" = [ "eos.asgard.yggdrasil" "eos" ];
        "::1" = [ "eos.asgard.yggdrasil" "eos" ];
      };

      firewall.enable = false;
      nftables = {
        enable = true;
        rulesetFile = ./ruleset.nft;
      };
    };

    services.resolved = {
      llmnr = "false";
    };

    zramSwap.enable = true;

    system.stateVersion = config.system.nixos.release; # No state


    time.timeZone = "Europe/Berlin";
    time.hardwareClockInLocalTime = true;
    i18n.defaultLocale = "en_DK.UTF-8";


    environment.systemPackages = with pkgs; [ cifs-utils ];

    security.pam.mount = {
      enable = true;
      extraVolumes = [
        "<volume sgrp=\"users\" fstype=\"cifs\" server=\"vidhar.lan.yggdrasil\" path=\"home-eos\" mountpoint=\"~\" />"
        "<volume sgrp=\"users\" fstype=\"cifs\" server=\"vidhar.lan.yggdrasil\" path=\"%(USER)\" mountpoint=\"/run/media/%(USER)/vidhar\" />"
      ];
    };


    services.xserver = {
      enable = true;
      displayManager.sddm = {
        enable = true;
        settings = {
          Users.HideUsers = "gkleen";
        };
      };
      desktopManager.plasma5.enable = true;

      videoDrivers = [ "nvidia" ];
    };
  };
}