# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).

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

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Kernel
  boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
  # Use the Grub boot loader.
  boot.loader.grub = {
	enable = true;
	zfsSupport = true;
	efiSupport = true;
	efiInstallAsRemovable = true;
	mirroredBoots = [
		{ devices = [ "nodev" ]; path  = "/boot"; }
	];
  };
  boot.supportedFilesystems = [ "zfs" ];
  boot.loader.grub.memtest86.enable = true;
  zramSwap = {
	enable = true;
	algorithm = "zstd";
  };

  # ZFS
  services.zfs.autoScrub.enable = true;
  services.zfs.trim.enable = true;

  # Firmware
  services.fwupd.enable = true;
  hardware.firmware = with pkgs; [ firmwareLinuxNonfree ];
  hardware.enableAllFirmware = true;
  hardware.enableRedistributableFirmware = true;

  # enable unfree
  nixpkgs.config.allowUnfree = true;

  # Network
  networking.hostName = "files";
  services.tailscale.enable = true;
  networking.networkmanager.enable = true;
  networking.hostId = "8425e349";

  # TimeZone
  time.timeZone = "Europe/Oslo";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";
   console = {
     font = "Lat2-Terminus16";
     keyMap = "no";
   };

  users.users.geir= {
     isNormalUser = true;
     extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
     packages = with pkgs; [
       tree fastfetch kitty 
     ];
   };

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    emacs zfs
    wget curl git 
  ];


  # Enable services
  services.openssh.enable = true;
  services.nfs.server.enable = true;
  services.nfs.server.exports = ''
	/mnt/storage	10.0.0.0/24(rw,fsid=0,no_subtree_check) 100.64.0.0/10(rw,fsid=0,no_subtree_check)
  '';

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ 2049  ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  networking.firewall.enable = false;

  system.stateVersion = "23.11"; 

}