# vim:fileencoding=utf-8:foldmethod=marker
{
  pkgs,
  inputs,
  username,
  ...
}:
{
  imports = [
    ./hardware-configuration.nix
    ./home.nix
  ];

  time.timeZone = "Europe/Paris";

  modules = {
    media.enableAll = true;
    fs.nfsEnable = true;

    system = {
      roles = {
        desktop.enable = true;
        gaming.enable = true;
      };

      outputs = {
        eDP-1 = {
          resX = 3840;
          resY = 2400;
          scale = 2.0;
        };
      };
      networking = {
        bluetooth.enable = true;
        wifi.enable = true;
      };
    };

    services = {
      cliphist.enable = true;
      nysh.enable = true;
      tailscale = {
        enable = true;
        tags = [ "client" ];
      };
      udev = {
        enable = true;
        libvirtHotplug."archlinux" = [
          "303a/1001/*" # Espressif JTG debug unit
        ];
      };
    };
  };

  # Bootloader.
  boot = {
    kernelPackages = pkgs.linuxPackages_latest;
    loader = {
      systemd-boot.enable = true;
      efi.canTouchEfiVariables = true;
    };
  };

  hardware.graphics.enable = true;

  xdg = {
    portal.enable = true;
    mime.enable = true;
  };

  specialisation = {
    gpu.configuration = {
      imports = [ inputs.nixos-hardware.nixosModules.dell-xps-15-9510-nvidia ];
    };
  };

  age = {
    identityPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
    secrets.rustypaste = {
      file = ../../secrets/rustypaste.age;
      mode = "440";
      group = "wheel";
    };
  };

  programs = {
    dconf.enable = true;
    fish.enable = true;
    firefox.enable = true;
    thunderbird.enable = true;
    sway.enable = true;
    hyprland.enable = true;
    pulseview.enable = true;
    gnupg.agent = {
      enable = true;
      enableSSHSupport = true;
    };
  };

  hardware.sane = {
    enable = true;
    extraBackends = [ pkgs.hplipWithPlugin ];
  };

  services = {
    displayManager.sddm.enable = true;
    dbus.enable = true;
    fwupd.enable = true;
    gvfs.enable = true;
    printing.enable = true;

    xserver.xkb = {
      layout = "fr";
      variant = "";
    };

    pipewire.enable = true;
    gnome.gnome-keyring.enable = true;
    openssh.enable = true;

    #: Power Consumption {{{
    logind = {
      lidSwitch = "suspend-then-hibernate";
      powerKey = "hibernate";
    };

    thermald.enable = true;

    auto-cpufreq.enable = true;

    upower = {
      enable = true;
      criticalPowerAction = "Hibernate";
    };
    #:}}}
  };

  console.keyMap = "fr";

  users = {
    defaultUserShell = pkgs.fish;
    users.${username} = {
      isNormalUser = true;
      createHome = true;
      extraGroups = [
        "networkmanager"
        "wheel"
        "audio"
        "libvirtd"
        "dialout" # Necessary for serial port interactions
      ];
    };
  };

  environment.variables = {
    ELECTRON_OZONE_PLATFORM_HINT = "auto";
    MOZ_ENABLE_WAYLAND = 1;
  };

  security.polkit.enable = true;

  virtualisation = {
    libvirtd.enable = true;
    docker = {
      enable = true;
      rootless.enable = true;
    };
  };

  programs.virt-manager.enable = true;

  programs.nix-ld.enable = true;

  environment.systemPackages = with pkgs; [
    shared-mime-info
    glib
    dconf
    xdg-utils
    brightnessctl
  ];

  system.stateVersion = "24.11";
}
