{ pkgs, lib, ... }:
with lib;
{

  nixpkgs.hostPlatform = {
    system = "x86_64-linux";
    config = "x86_64-unknown-linux-gnu";
  };
  _module.args.CPUs = 4;
  hardware.cpu.amd.updateMicrocode = true;
  powerManagement.cpuFreqGovernor = mkDefault "ondemand";

  # Too CPU hungry for this hardware, for too little Mio saved
  nix.settings.auto-optimise-store = false;

  # https://insanity.industries/post/sata-power-consumption/
  services.udev.extraRules = ''
    SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="med_power_with_dipm"
  '';

  boot.loader = {
    grub = {
      enable = true;
      version = 2;
      copyKernels = true;
      configurationLimit = mkDefault 1;
      # efiSupport = true;
      # In case canTouchEfiVariables doesn't work
      #efiInstallAsRemovable = true;
      devices = [
        # Completed in the importing configuration
      ];
      /*
        mirroredBoots = [
      { devices = [ "${disk_id}" ];
        path    = "/boot${bootnum}";
      }
        ];
      */
    };
    /*
      efi = {
      canTouchEfiVariables = true;
      efiSysMountPoint = "/boot/efi";
      };
    */
  };

  boot.initrd = {
    availableKernelModules = [
      "ahci"
      "ehci_pci"
      "sd_mod"
      "sg"
      "uas"
    ];
    kernelModules = [
      # Ethernet driver
      "igb"
      # Enable to switch to stage-2 from the SD card
      "sdhci_pci"
    ];
  };

  boot.consoleLogLevel = mkDefault 7;
  boot.kernelParams = [
    "gfxpayload=text"
    "console=ttyS0,115200n8"
    # Use arc_summary to print stats
    #"zfs.zfs_arc_max=${toString (500 * 1024 * 1024)}" # bytes
  ];

  environment.systemPackages = [
    pkgs.flashrom
    pkgs.pciutils
  ];
}