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

{
  # Kernel configuration
  boot = {
    kernelPackages = pkgs.linuxPackages_latest;
    kernelParams = [ "zfs.zfs_arc_max=536870912" ];
    kernelModules = [ "i915" "acpi_call" ];
    extraModulePackages = with config.boot.kernelPackages; [ acpi_call ];
    supportedFilesystems = [ "zfs" ];
    zfs.requestEncryptionCredentials = true;
  };

  # Intel CPU tweaks
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

  hardware.opengl.extraPackages = with pkgs; [
    vaapiIntel
    vaapiVdpau
    libvdpau-va-gl
  ];

  # Bootloader configuration
  boot.loader = {
    efi.canTouchEfiVariables = true;
    systemd-boot = {
      enable = true;
      configurationLimit = 50;
    };
  };

  # Run Nix garbage collector, while avoiding compiling
  nix = {
    gc = {
      automatic = true;
      options = "--delete-older-than 14d";
    };
    extraOptions = ''
      keep-outputs = true
      gc-keep-outputs = true
    '';
  };

  # Clean tmp directory on shutdown
  boot.cleanTmpDir = true;

  # Rotate logs after 7 days
  services.journald.extraConfig = "SystemMaxFiles=7";

  # Allow propietary software
  nixpkgs.config.allowUnfree = true;

  # Scrub zpool monthly
  services.zfs.autoScrub = {
    enable = true;
    interval = "monthly";
  };

  # Set timezone and synchronize NTP
  time.timeZone = "Europe/Brussels";
  services.timesyncd.enable = true;

  # Enable the TLP daemon
  services.tlp.enable = true;

  # NixOS version
  system.stateVersion = "20.09";

  # Import other configuration modules
  imports = [
    ./modules/software.nix
    ./modules/networking.nix
    ./modules/gui.nix
    ./modules/datasync.nix
    ./modules/audio.nix
    ./modules/home.nix
    ./modules/hardware-configuration.nix
  ];

}