{ config, pkgs, lib, username, fullname, ... }:
let
  inherit (config) machine;
  isMobile = machine == "air";

  hashedPassword =
      if machine == "earth" then
        "$y$j9T$rpQs/Fnsxh4DNw4qDSvTu.$nzA1EskOnWrYM.Iba7q73O.QPEn3DFWrX2.KY8mKza."
      else if machine == "fire" then
        "$y$j9T$EXc0TFu9LQhQ9YGrOkb7u0$LpwNG0XpUIVSltLqUw7CAOLSsI2rZr1RTBnJai5dkM7"
      else # if machine == "air"
        "$y$j9T$zF34p.W/HFKrWde5Rb1nq/$1Q5IN9IT.IQ6SLg8InUZM5L27.jQV.cRtNENnUPp0ZC";
in
{
  nix.package = pkgs.nixVersions.latest;
  nix.settings.auto-optimise-store = true;
  nix.extraOptions = ''
    experimental-features = nix-command flakes ca-derivations
    restrict-eval = false
  '';

  nixpkgs.system = if isMobile then "aarch64-linux" else "x86_64-linux";
  nixpkgs.config.allowUnfree = true;

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = !isMobile;
  boot.loader.efi.canTouchEfiVariables = !isMobile;

  networking.hostName = "toki-${machine}";
  networking.wireless.enable = false;
  networking.networkmanager.enable = true;

  # Power button settings
  services.logind.settings.Login = {
    HandlePowerKey = "ignore";
    HandlePowerKeyLongPress = "poweroff";
  };

  # Set your time zone.
  time.timeZone = "America/New_York";

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  services.pipewire.enable = true;
  services.pipewire.pulse.enable = true;
  services.pipewire.wireplumber.enable = true;

  hardware.graphics.enable = true;

  users.mutableUsers = false;
  users.users.${username} = {
    isNormalUser = true;
    description = fullname;
    extraGroups = [ "wheel" "networkmanager" "video" ]
                  ++ lib.optionals isMobile [ "dialout" "feedbackd" ];
    shell = pkgs.fish;
    inherit hashedPassword;
  };
  users.users.root = { inherit hashedPassword; };
  nix.settings.trusted-users = [ "root" username ];


  fonts = {
    enableDefaultPackages = true;
    packages = with pkgs; [
      # Monospace
      victor-mono
      jetbrains-mono
      nerd-fonts.victor-mono
      nerd-fonts.jetbrains-mono
      nerd-fonts.symbols-only
      font-awesome

      # Regular
      noto-fonts
      noto-fonts-cjk-sans
      noto-fonts-color-emoji
      overpass

      # Display
      quicksand

      # Unicode
      symbola
    ];

    fontconfig = {
      enable = true;
      defaultFonts = {
        serif = lib.optional (!isMobile) "Noto Serif";
        sansSerif = lib.optional (!isMobile) "Noto Sans";
        monospace = [ "VictorMono" ];
      };
    };
  };

  environment.sessionVariables.GTK_THEME = "Adwaita:dark";

  services.openssh.enable = true;

  programs.gnupg.agent = {
    enable = true;
    pinentryPackage = pkgs.pinentry-gnome3;
  };

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "21.11"; # Did you read the comment?
}
