#
# Our various packages; generated for each system.
#
{
  flake-utils,
  deprekages,
  nixpkgs,
  esp-dev,
}:

flake-utils.lib.eachDefaultSystem (
  system:
  let
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };
    callPackage = pkgs.callPackage;
  in
  {
    # The packages themselves,
    packages = rec {
      # fonts
      font-monolisa = callPackage ../fonts/monolisa.nix { };
      font-codicon = callPackage ../fonts/codicon.nix { };
      font-manrope = callPackage ../fonts/manrope.nix { };
      font-phantom-sans = callPackage ../fonts/phantomsans.nix { };
      font-ia-writer = callPackage ../fonts/iawriter.nix { };
      font-pack-cyberpunk = callPackage ../fonts/cyberpunk { };

      # scientific things
      ffts = callPackage ./scopehal-apps/ffts.nix { };
      libsigrok4DSL = callPackage ./scopehal-apps/libsigrok4DSL.nix { };
      vulkan-sdk = callPackage ./scopehal-apps/vulkan-sdk.nix { };

      # apps
      navit = callPackage ./navit.nix { };
      navit-with-maps = callPackage ./navit.nix { with_maps = true; };
      binary-ninja = callPackage ./binary-ninja.nix { inherit svd2py; };
      argos = callPackage ./argos.nix { };
      todoist-electron = callPackage ./todoist-electron.nix { };
      home-assistant-desktop = callPackage ./home-assistant-desktop/x86_64-linux.nix { };
      flexbv = callPackage ./flexbv.nix { };
      glowing-bear-desktop = callPackage ./glowing-bear-desktop.nix { };
      hrvst-cli = callPackage ./hrvst-cli { };
      notion-app = callPackage ./notion-app { inherit _7zz; };
      gfn-electron = callPackage ./geforce-now { };
      whph = callPackage ./whph.nix { };

      # utilities
      ykush = callPackage ./ykush.nix { };
      wsl-gpg-forward = callPackage ./windows/gpg-forward.nix { };
      oxfs = callPackage ./oxfs.nix { };
      pcsclite = callPackage ./pcsclite.nix { };
      humanfx = callPackage ./humanfx { };
      clipboard-sync = callPackage ./clipboard-sync.nix { };
      vsmartcard = callPackage ./vsmartcard.nix { };
      pcsc-relay = callPackage ./pcsc-relay.nix { };
      neard = callPackage ./neard.nix { };
      libnfc = callPackage ./libnfc.nix { inherit libnfc-nci; };
      jadx = callPackage ./jadx { };
      firefox-webserial = callPackage ./firefox-webserial { inherit ws-server; };
      ryzen-ppd = callPackage ./ryzen-ppd { };
      avbroot = callPackage ./avbroot { };
      okc-agents = callPackage ./okc-agents.nix { };
      _7zz = pkgs._7zz.override { useUasm = true; };
      mergiraf = callPackage ./mergiraf.nix { };
      vja = callPackage ./vja.nix { };
      gimgtools = callPackage ./gimgtools.nix { };

      # lab tools
      librevna = callPackage ./librevna { };
      rfe-fwupdate = callPackage ./rfe-fwupdate.nix { };
      rfe-touch = callPackage ./rfe-touch.nix { };
      rfe-signal = callPackage ./rfe-signal.nix { };
      dsview = pkgs.libsForQt5.callPackage ./dsview { };
      scopehal-apps = callPackage ./scopehal-apps { deprekages = deprekages.${system}; };
      scopehal-sigrok-bridge = callPackage ./scopehal-apps/sigrok-bridge.nix {
        deprekages = deprekages.${system};
      };

      # libraries
      libnfc-nci = callPackage ./libnfc-nci { };
      ws-server = callPackage ./ws-server { };
      rubyPackages = callPackage ./ruby-gems.nix { };

      # jetbrains products
      jetbrains-jdk = callPackage ./jetbrains-jdk.nix { };
      jetbrains = import ./jetbrains.nix {
        inherit pkgs;
        jdk = jetbrains-jdk;
      };

      # pytho modules
      svd2py = callPackage ./svd2py.nix { };

      # kernel modules
      linuxPackages_i915-sriov = callPackage ./i915-sriov/kernel.nix { };
      i915-sriov = callPackage ./i915-sriov { linuxPackages = linuxPackages_i915-sriov; };
      linux-nfc-lenovo = callPackage ./linux-nfc-lenovo { };

      # hw support
      dell = callPackage ./dell { };
      synatudor = callPackage ./synatudor { };
      gps-share = callPackage ./gps-share.nix { };

      # udev rules~
      t5-udev-rules = callPackage ./t5-udev-rules { };
      ykush-udev-rules = callPackage ./ykush-udev-rules { };
      dreamsource-udev-rules = callPackage ./dreamsource-udev-rules { };
      hantek-udev-rules = callPackage ./hantek-udev-rules { };
      linux-nfc-lenovo-udev-rules = callPackage ./linux-nfc-lenovo/udev.nix { };

      # color profiles
      framework-13-icm = callPackage ./framework-13-icm { };

      # weechat
      weechat-discord = callPackage ./weechat-discord { };

      # kakoune
      kak-tree-sitter = callPackage ./kak-tree-sitter { };

      # vscode
      vscode-extensions = callPackage ./vscode-extensions.nix { };

      # plasma
      kde-karousel = callPackage ./kde-karousel.nix { };

      # esp32
      esp-env = esp-dev.${system}.esp-idf-full;

      # xonsh and xontribs
      xontrib-whole-word-jumping = callPackage ./xontrib-whole-word-jumping.nix { };
      xontrib-term-integrations = callPackage ./xontrib-term-integrations.nix { };
      xontrib-prompt-starship = callPackage ./xontrib-prompt-starship.nix { };
      xontrib-prompt-bar = callPackage ./xontrib-prompt-bar.nix { };
      xontrib-termcolors = callPackage ./xontrib-termcolors.nix { };
      xontrib-sh = callPackage ./xontrib-sh.nix { };

      xonsh-with-xontribs = pkgs.xonsh.override {
        extraPackages = pythonPackages: [
          xontrib-whole-word-jumping
          xontrib-term-integrations
          xontrib-prompt-starship
          xontrib-prompt-bar
          xontrib-sh
        ];
      };
    };
  }
)
