dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
912 stars 213 forks source link

"Dynamic records" / --maps support in dhall-toml #2509

Closed ELLIOTTCABLE closed 10 months ago

ELLIOTTCABLE commented 1 year ago

I'm new, so maybe this is the wrong way to go about the problem; but I'd like to generate a config like the following (for rtx's ~/.config/rtx/config.toml) in a relatively D.R.Y. / deduped way:

[plugins]
cabal = 'https://github.com/sestrella/asdf-ghcup.git'
ghc = 'https://github.com/sestrella/asdf-ghcup.git'
hls = 'https://github.com/sestrella/asdf-ghcup.git'
stack = 'https://github.com/sestrella/asdf-ghcup.git'

[tools]
cabal = "latest"
dotnet = "latest"
golang = "latest"
hls = "latest"
jq = "latest"
lua = "latest"
nodejs = "latest"
opam = "latest"
php = "latest"
purescript = "latest"
python = "latest"
racket = "latest"
ruby = "latest"
rust = "latest"

Reading the docs, it feels like this needs "Dynamic records" support (or dependent typing 😅); but that doesn't seem to be supported by dhall-toml as yet:

$ dhall-to-toml --file Dotfiles/config/rtx/config.dhall
[[plugins]]
  mapKey = "cabal"
  mapValue = "https://github.com/sestrella/asdf-ghcup.git"

[[plugins]]
  mapKey = "ghc"
  mapValue = "https://github.com/sestrella/asdf-ghcup.git"

[[plugins]]
  mapKey = "hls"
  mapValue = "https://github.com/sestrella/asdf-ghcup.git"

[[plugins]]
  mapKey = "stack"
  mapValue = "https://github.com/sestrella/asdf-ghcup.git"
ELLIOTTCABLE commented 1 year ago

I am, of course, able to circumvent this by using dhall-to-json instead, and piping thru yq for instance:

$ dhall-to-json --file Dotfiles/config/rtx/config.dhall | yq --toml-output '.'
Gabriella439 commented 1 year ago

yeah, i'm pretty sure this is fixable by adding dhall-toml support for the Prelude.Map type. i'm working on this