let owner = "ehmry"

let Genode = env:DHALL_GENODE

let Prelude = Genode.Prelude

let List/map = Prelude.List.map

let XML = Prelude.XML

let XML/Type =
        /home/repo/dhall-lang/Prelude/XML/Type sha256:461930f3aab769ba537d1a4fd71f411504b0c8d1c1a78d65177be8ded0df8a5c
      ? /home/repo/dhall-lang/Prelude/XML/Type

let Entry = { info : Text, name : Text, version : Text }

let ownedEntry =
        λ(owner : Text)
      → λ(e : Entry)
      → XML.leaf
        { name =
            "pkg"
        , attributes =
            [ { mapKey = "info", mapValue = e.info }
            , { mapKey =
                  "path"
              , mapValue =
                  "${owner}/pkg/${e.name}/${e.version}"
              }
            ]
        }

let entry = ownedEntry owner

let subIndex =
        λ(name : Text)
      → λ(entries : List Entry)
      → XML.element
        { name =
            "index"
        , attributes =
            [ { mapKey = "name", mapValue = name } ]
        , content =
            List/map Entry XML/Type entry entries
        }

let emu =
      subIndex
      "Emulators and game engines"
      [ ./depot/pkg/fceumm/current/index.dhall
      , ./depot/pkg/gambatte/current/index.dhall
      , ./depot/pkg/snes9x/current/index.dhall
      , ./depot/pkg/mgba/current/index.dhall
      ]

let games =
      subIndex
      "Games"
      [ ./depot/pkg/libretro-2048/current/index.dhall
      , ./depot/pkg/tyrquake/current/index.dhall
      ]

let streams =
      subIndex
      "Streams"
      [ ./depot/pkg/ifm1/current/index.dhall
      , ./depot/pkg/ifm2/current/index.dhall
      , ./depot/pkg/ifm3/current/index.dhall
      ]

let utilities =
      subIndex
      "Utilities"
      [ ./depot/pkg/depot_9P/current/index.dhall
      , ./depot/pkg/show_input/current/index.dhall
      , ./depot/pkg/nic_bus/current/index.dhall
      , ./depot/pkg/noux-system/current/index.dhall
      , ./depot/pkg/backdrop/current/index.dhall
      ]

let index =
      XML.element
      { name =
          "index"
      , attributes =
          XML.emptyAttributes
      , content =
          [ emu
          , games
          , streams
          , utilities
          , XML.text
            "<pkg path=\"cnuke/pkg/bsd_audio_drv/2019-07-02\" info=\"OpenBSD audio driver\"/>"
          ]
      }

in  XML.render index
