{
  config,
  lib,
  namespace,
  ...
}:
let
  inherit (lib.${namespace}) mkOpt mkReverseProxyOpt;
  cfg = config.${namespace}.services.glance;
in
with lib;
{
  options.${namespace}.services.glance = {
    enable = mkEnableOption "glance service";

    port = mkOpt types.int 80 "Port for glance to be hosted on";

    localAddress = mkOpt types.str "127.0.0.1" "local address of the service";

    dataDir = mkOpt types.str "" "Path to the data dir";

    reverseProxy = mkReverseProxyOpt;
  };

  config = lib.mkIf cfg.enable {
    services.glance = {
      enable = true;
      openFirewall = true;
      settings = {
        server = {
          host = "0.0.0.0";
          port = cfg.port;
        };
        pages = [
          {
            name = "Startpage";
            width = "default";
            hide-desktop-navigation = true;
            center-vertically = true;
            columns = [
              {
                size = "small";
                widgets = [
                  {
                    type = "calendar";
                    first-day-of-week = "sunday";
                  }
                  {
                    type = "weather";
                    units = "metric";
                    hour-format = "12h";
                    location = "Saint Paul, Minnesota, United States";
                  }
                  {
                    type = "server-stats";
                    servers = [
                      {
                        type = "local";
                        name = "Jallen-NAS";
                        cpu-temp-sensor = "/sys/class/hwmon/hwmon2/temp2_input";
                        mountpoints = {
                          "/home" = {
                            name = "Home";
                          };
                          "/media/nas/main" = {
                            name = "nas_pool";
                          };
                        };
                      }
                    ];
                  }
                ];
              }
              {
                size = "full";
                widgets = [
                  {
                    type = "search";
                    autofocus = true;
                    search-engine = "duckduckgo";
                    bangs = [
                      {
                        title = "YouTube";
                        shortcut = "!yt";
                        url = "https://www.youtube.com/results?search_query={QUERY}";
                      }
                    ];
                  }
                  {
                    type = "monitor";
                    cache = "1m";
                    title = "Services";
                    sites = [
                      {
                        title = "Actual";
                        url = "https://actual.mjallen.dev/";
                        icon = "si:actualbudget";
                      }
                      {
                        title = "Jellyfin";
                        url = "https://jellyfin.mjallen.dev/";
                        icon = "si:jellyfin";
                      }
                      {
                        title = "Gitea";
                        url = "https://gitea.mjallen.dev/";
                        icon = "si:gitea";
                      }
                      {
                        title = "Nextcloud";
                        url = "https://cloud.mjallen.dev/";
                        icon = "si:nextcloud";
                      }
                      {
                        title = "Immich";
                        url = "https://immich.mjallen.dev/";
                        icon = "si:immich";
                      }
                      {
                        title = "AdGuard Home";
                        url = "http://10.0.1.2:3000/";
                        icon = "si:adguard";
                        allow-insecure = true;
                      }
                      {
                        title = "Home Assistant";
                        url = "https://hass.mjallen.dev/";
                        icon = "si:homeassistant";
                      }
                      {
                        title = "Manyfold";
                        url = "http://10.0.1.3:3214/collections";
                        icon = "sh:Manyfold";
                        allow-insecure = true;
                      }
                      {
                        title = "Sonarr";
                        url = "http://10.0.1.3:8989/";
                        icon = "si:sonarr";
                        allow-insecure = true;
                        basic-auth = {
                          username = "mjallen";
                          password = "BogieDudie1";
                        };
                      }
                      {
                        title = "Radarr";
                        url = "http://10.0.1.3:7878/";
                        icon = "si:radarr";
                        allow-insecure = true;
                        basic-auth = {
                          username = "mjallen";
                          password = "BogieDudie1";
                        };
                      }
                      # {
                      #   title = "";
                      #   url = "";
                      #   icon = "si:";
                      # }
                    ];
                  }
                  {
                    type = "bookmarks";
                    groups = [
                      {
                        title = "General";
                        links = [
                          {
                            title = "Gmail";
                            url = "https://mail.google.com/mail/u/0/";
                          }
                          {
                            title = "Proton Mail";
                            url = "https://mail.proton.me/u/0/inbox";
                          }
                          {
                            title = "MyNixOS";
                            url = "https://www.mynixos.com/";
                          }
                          {
                            title = "Github";
                            url = "https://github.com/";
                          }
                        ];
                      }
                      {
                        title = "Entertainment";
                        links = [
                          {
                            title = "YouTube";
                            url = "https://www.youtube.com/";
                          }
                          {
                            title = "Prime Video";
                            url = "https://www.primevideo.com/";
                          }
                          {
                            title = "Disney+";
                            url = "https://www.disneyplus.com/";
                          }
                        ];
                      }
                      {
                        title = "Social";
                        links = [
                          {
                            title = "Reddit";
                            url = "https://www.reddit.com/";
                          }
                          {
                            title = "Twitter";
                            url = "https://twitter.com/";
                          }
                          {
                            title = "Instagram";
                            url = "https://www.instagram.com/";
                          }
                        ];
                      }
                    ];
                  }
                ];
              }
            ];
          }
        ];
      };
    };
  };
}
