{
  config,
  lib,
  namespace,
  ...
}:
let
  name = "glance";
  cfg = config.${namespace}.services.${name};

  glanceConfig = lib.${namespace}.mkModule {
    inherit config name;
    description = "glance";
    options = { };
    moduleConfig = {
      sops = {
        secrets = {
          "jallen-nas/glance/arr-username" = {
            sopsFile = (lib.snowfall.fs.get-file "secrets/nas-secrets.yaml");
          };
          "jallen-nas/glance/arr-password" = {
            sopsFile = (lib.snowfall.fs.get-file "secrets/nas-secrets.yaml");
          };
        };
        templates = {
          "glance.env" = {
            mode = "660";
            restartUnits = [ "glance.service" ];
            content = ''
              ARR_USER=${config.sops.placeholder."jallen-nas/glance/arr-username"}
              ARR_PASS=${config.sops.placeholder."jallen-nas/glance/arr-password"}
            '';
          };
        };
      };

      services.glance = {
        enable = true;
        openFirewall = true;
        environmentFile = config.sops.templates."glance.env".path;
        settings = {
          server = {
            host = "0.0.0.0";
            port = cfg.port;
          };
          pages = [
            {
              name = "Startpage";
              width = "default";
              # tab = "First";
              hide-desktop-navigation = true;
              center-vertically = true;
              columns = [
                {
                  size = "small";
                  widgets = [
                    {
                      type = "calendar";
                      first-day-of-week = "sunday";
                    }
                    {
                      type = "weather";
                      units = "imperial";
                      hour-format = "12h";
                      location = "Saint Paul, Minnesota, United States";
                    }
                    {
                      type = "server-stats";
                      servers = [
                        {
                          type = "local";
                          name = "Jallen-NAS";
                          cpu-temp-sensor = "/sys/devices/pci0000:00/0000:00:08.1/0000:cd:00.0/hwmon/hwmon*/temp1_input"; # Tctl
                          mountpoints = {
                            "/home" = {
                              name = "Home";
                            };
                            "/media/nas/main" = {
                              name = "nas_pool";
                            };
                          };
                        }
                      ];
                    }
                  ];
                }
                {
                  size = "full";
                  # tab = "First";
                  widgets = [
                    {
                      type = "search";
                      autofocus = true;
                      search-engine = "google";
                      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 = "Code Server";
                          url = "http://10.0.1.3:4444/";
                          icon = "si:vscodium";
                          allow-insecure = true;
                        }
                        {
                          title = "NAS KVM";
                          url = "http://nas-kvm.local/";
                          icon = "si:nanokvm";
                          allow-insecure = true;
                        }
                        {
                          title = "Sonarr";
                          url = "http://10.0.1.3:8989/";
                          icon = "si:sonarr";
                          allow-insecure = true;
                          basic-auth = {
                            username = "\${ARR_USER}";
                            password = "\${ARR_PASS}";
                          };
                        }
                        {
                          title = "Radarr";
                          url = "http://10.0.1.3:7878/";
                          icon = "si:radarr";
                          allow-insecure = true;
                          basic-auth = {
                            username = "\${ARR_USER}";
                            password = "\${ARR_PASS}";
                          };
                        }
                        {
                          title = "Sabnzbd";
                          url = "http://10.0.1.3:8280/";
                          icon = "si:sabnzbd";
                          allow-insecure = true;
                          basic-auth = {
                            username = "\${ARR_USER}";
                            password = "\${ARR_PASS}";
                          };
                        }
                        # {
                        #   title = "";
                        #   url = "";
                        #   icon = "si:";
                        # }
                      ];
                    }
                    {
                      type = "bookmarks";
                      # tab = "First";
                      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/";
                            }
                          ];
                        }
                      ];
                    }
                    {
                      type = "reddit";
                      subreddit = "hockey";
                    }
                    {
                      type = "reddit";
                      subreddit = "formula1";
                    }
                  ];
                }
              ];
            }
            # {
            #   name = "test";
            #   width = "default";
            #   hide-desktop-navigation = true;
            #   center-vertically = true;
            #   columns = [
            #     {
            #       size = "small";
            #       widgets = [
            #         {
            #           type = "adguard";
            #           url = "http://pi4.local:3000";
            #           username = "mjallen";
            #           password = "BogieDudie1";
            #         }
            #       ];
            #     }
            #   ];
            # }
          ];
        };
      };
    };
  };
in
{
  imports = [ glanceConfig ];
}
