#
# Our generic NixOS configuration for all systems.
# Individual machines are set up in ../flake.nix and their ./hosts entries.
#
# vim: et:ts=2:sw=2:
#
{
  pkgs,
  deprekages,
  talon,
  ...
}:

{
  # Ensures the system state isn't changed breakingly (e.g. by updating
  # a program to a version that takes a newer data format) from the version
  # listed here.
  system.stateVersion = "23.11";

  #
  # Generic system settings.
  #
  time.timeZone = "Europe/Amsterdam";
  i18n.defaultLocale = "nl_NL.UTF-8";

  # Allow use of e.g. 'nix search' and flakes.
  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];

  # Allow use of unfree software.
  nixpkgs.config.allowUnfree = true;

  # You can trust us. I swear.
  nix.settings.trusted-users = [ "deprekated" ];

  # Xonsh is currently broken in unstable.
  # Add a harmless workaround to all of our systems.
  imports = [
    ./overlays/always-wrap-xonsh.nix
  ];

  #
  # General tweaks and fixes.
  #

  #
  # Users.
  #

  # Create a device groups, which are useful for USB stuffs.
  users.groups.plugdev = { };
  users.groups.input = { };

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.deprekated = {
    isNormalUser = true;
    description = "Kate Adkins";
    uid = 1000;

    extraGroups = [
      "audio"
      "disk"
      "dialout"
      "libvirtd"
      "networkmanager"
      "plugdev"
      "qmemu-libvirtd"
      "video"
      "wheel"
      "input"
      "kvm"
    ];

    # Use xonsh as our default shell.
    shell = deprekages.xonsh-with-xontribs;
  };

  programs.xonsh = {
    enable = true;
    package = deprekages.xonsh-with-xontribs;

    # Unfortunately, repeating this here is temporarily necessary due to NixOS module wonk.
    extraPackages = [
      deprekages.xontrib-whole-word-jumping
      deprekages.xontrib-term-integrations
      deprekages.xontrib-prompt-starship
      deprekages.xontrib-prompt-bar
      deprekages.xontrib-sh
    ];
  };

  #
  # Services
  #
  services.pcscd = {
    enable = true;
  };
  services.openssh.enable = true;
  services.mullvad-vpn.enable = true;
  virtualisation.docker.enable = true;

  services.udev.packages =
    [
      pkgs.minipro
    ]
    ++ (
      if pkgs.stdenv.isAarch64 then
        [ ]
      else
        [
          #talon.default
        ]
    );

  services.fwupd.enable = true;

  # Use avahi for local DNS.
  services.avahi = {
    enable = true;
    nssmdns4 = true;
    nssmdns6 = true;
    publish = {
      enable = true;
      userServices = true;
    };
  };

  # No, you haven't doxed us.
  # This is just the location of Amsterdam =P.
  location = {
    provider = "geoclue2";
    latitude = 52.377956;
    longitude = 4.897070;
  };
}
