{ flake, osConfig, ... }:
let
  inherit (flake.config.machines.devices) deimos;
  hostname = osConfig.networking.hostName;

  configPath = ./config;
  flakedPath = configPath + /flake;
  regularSearchEngines =
    let
      files = builtins.attrNames (builtins.readDir configPath);
    in
    builtins.foldl' (
      emptySet: searchEngine: emptySet // (import (configPath + "/${searchEngine}"))
    ) { } (builtins.filter (name: builtins.match ".*\\.nix$" name != null) files);

  flakedSearchEngines =
    let
      files = builtins.attrNames (builtins.readDir flakedPath);
    in
    builtins.foldl' (
      emptySet: searchEngine:
      emptySet
      // (import (flakedPath + "/${searchEngine}") {
        inherit
          flake
          osConfig
          ;
      })
    ) { } (builtins.filter (name: builtins.match ".*\\.nix$" name != null) files);

  aggregatedSearchEngines = regularSearchEngines // flakedSearchEngines;
in
{
  search = {
    force = true;
    default = "Brave";
    engines = aggregatedSearchEngines;
    order = [
      "AlternativeTo"
      "Brave"
      "Core Radio"
      "Hackage"
      "Hoogle"
      "Jellyfin"
      "Nix Home Manager"
      "Nix Options"
      "Nix Packages"
      "Nix Wiki"
      "PeerTube"
      "SearXNG"
      "Sci-Hub"
      "Torrent Leech"
      "Urban Dictionary"
      "Wikipedia"
      "Youtube"
    ];
  };
}
