0 | module Pack.Config.TOML
  1 |
  2 | import Data.List1
  3 | import Data.String
  4 |
  5 | import Pack.Config.Types
  6 | import Pack.Core
  7 | import Pack.Database
  8 |
  9 | import Text.TOML
 10 |
 11 | %default total
 12 |
 13 | export
 14 | FromTOML Autoload where
 15 |   fromTOML dir v = case v of
 16 |     TStr "none"      => Right NoPkgs
 17 |     TStr "installed" => Right Installed
 18 |     TStr "autolibs"  => Right AutoLibs
 19 |     _                => AutoPkgs <$> fromTOML dir v
 20 |
 21 | export
 22 | FromTOML Codegen where
 23 |   fromTOML = tmap Types.fromString
 24 |
 25 | extractString : (errMsg : String) -> (v : TomlValue) -> Either TOMLErr String
 26 | extractString _ (TStr s) = Right s
 27 | extractString errMsg _ = Left $ WrongType [] errMsg
 28 |
 29 | export
 30 | FromTOML RlwrapConfig where
 31 |   fromTOML _ (TBool x)  = Right $ if x then UseRlwrap [] else DoNotUseRlwrap
 32 |   fromTOML _ (TStr str) = Right $ UseRlwrap [NoEscape str]
 33 |   fromTOML _ (TArr xs)  =
 34 |     map (UseRlwrap . fromStrList) $
 35 |       traverse (extractString "array of strings") xs
 36 |   fromTOML _ _ = Left $ WrongType [] "boolean, string or array of strings"
 37 |
 38 | export
 39 | FromTOML CmdArgList where
 40 |   fromTOML _ (TStr str) = Right $ [NoEscape str]
 41 |   fromTOML _ (TArr xs)  =
 42 |     fromStrList <$>
 43 |       traverse (extractString "array of strings") xs
 44 |   fromTOML _ _ = Left $ WrongType [] "string or array of strings"
 45 |
 46 | export
 47 | FromTOML UserConfig where
 48 |   fromTOML f v =
 49 |       [| MkConfig
 50 |           (maybeValAt "collection" f v)
 51 |           (maybeValAt "idris2.url" f v)
 52 |           (maybeValAt "idris2.commit" f v)
 53 |           (toList <$> maybeValAt "idris2.commit" f v)
 54 |           (maybeValAt "pack.url" f v)
 55 |           (maybeValAt "pack.commit" f v)
 56 |           (maybeValAt "idris2.scheme" f v)
 57 |           (maybeValAt "idris2.bootstrap" f v)
 58 |           (maybeValAt "idris2.bootstrap-stage3" f v)
 59 |           (maybeValAt "install.safety-prompt" f v)
 60 |           (maybeValAt "install.gc-prompt" f v)
 61 |           (maybeValAt "install.gc-purge" f v)
 62 |           (maybeValAt "install.warn-depends" f v)
 63 |           (maybeValAt "admin.skip-tests" f v)
 64 |           (maybeValAt "install.whitelist" f v)
 65 |           (maybeValAt "install.with-src" f v)
 66 |           (maybeValAt "install.with-docs" f v)
 67 |           (maybeValAt "install.use-katla" f v)
 68 |           (pure Nothing)
 69 |           (maybeValAt "idris2.repl.rlwrap" f v)
 70 |           (maybeValAt "idris2.extra-args" f v)
 71 |           (maybeValAt "install.libs" f v)
 72 |           (maybeValAt "install.apps" f v)
 73 |           (maybeValAt "idris2.repl.autoload" f v)
 74 |           (maybeValAt "custom" f v)
 75 |           (pure Nothing)
 76 |           (pure Nothing)
 77 |           (maybeValAt "idris2.codegen" f v)
 78 |           (pure Nothing)
 79 |           (maybeValAt "log" f v)
 80 |           (maybeValAt "idris2.git" f v)
 81 |       |]
 82 |
 83 | ||| Initial content of an auto-generated `PACK_USER_DIR/pack.toml` file.
 84 | export
 85 | initToml : (scheme : String) -> String
 86 | initToml scheme = """
 87 |   [install]
 88 |
 89 |   # Whether to install packages together with their
 90 |   # sources or not. This is mainly useful for programmers
 91 |   # who have set their editor up with some *go to definition*
 92 |   # functionality (for instance by using idris2-lsp with neovim).
 93 |   # with-src   = true
 94 |
 95 |   # Whether to install API docs together with installed
 96 |   # libraries.
 97 |   # with-docs = false
 98 |
 99 |   # Whether to use katla to generate HTML links to
100 |   # semantically highlighted API sources
101 |   # use-katla = false
102 |
103 |   # Whether to prompt the user before building or installing
104 |   # packages or applications with custom build hooks in their
105 |   # `.ipkg` file.
106 |   # safety-prompt = true
107 |
108 |   # Whether to prompt the user before running the garbage collector
109 |   # via command `gc`.
110 |   # gc-prompt = true
111 |
112 |   # Whether to remove all outdated libraries and applications during
113 |   # garbage collection (command `gc`).
114 |   # gc-purge = false
115 |
116 |   # Whether to issue a warning in presence of a local `depends` directory
117 |   # which might interfere with the libraries managed by pack
118 |   # warn-depends = true
119 |
120 |   # List of packages and apps with custom build hooks we trust to
121 |   # be safe. This gives more fine grained control over package safety
122 |   # than `safety-prompt`.
123 |   # whitelist = [ "pack", "idris2-lsp" ]
124 |
125 |   # Must-have libraries. These will be installed automatically
126 |   # when using a new package collection.
127 |   # Example: `libs       = [ "toml", "elab-util" ]`
128 |   # libs       = []
129 |
130 |   # Must-have applications. These will be installed automatically
131 |   # when using a new package collection.
132 |   # Example: `apps       = [ "idris2-lsp" ]`
133 |   # apps       = []
134 |
135 |   [pack]
136 |
137 |   # Override this to use a custom Git repo for pack
138 |   # url = "https://github.com/stefan-hoeck/idris2-pack"
139 |
140 |   # Override this to use a custom commit and branch for pack
141 |   # commit = "latest:main"
142 |
143 |   [idris2]
144 |
145 |   # Whether to build Idris2 with its bootstrap compiler.
146 |   # Bootstrapping takes longer than building with an existing
147 |   # Idris2 installation, but it will work even if the existing
148 |   # Idris2 compiler is outdated.
149 |   # bootstrap  = false
150 |
151 |   # Whether to rebuild Idris2 when bootstrapping, using the newly
152 |   # built compiler. Produces a more optimised final executable,
153 |   # but increases build time.
154 |   # bootstrap-stage3 = true
155 |
156 |   # Name or path to the scheme executable to use.
157 |   scheme      = "\{scheme}"
158 |
159 |   # Default code generator to us
160 |   # codegen     = "chez"
161 |
162 |   # Set this to `true` in order to run REPL sessions from within
163 |   # `rlwrap`. This will give you additional features such as a
164 |   # command history.
165 |   # Alternatively, you can pass additional command-line arguments
166 |   # to `rlwrap` by setting this to a string or an array of strings,
167 |   # e.g. to "-pGreen -aN" or ["-pGreen", "--no-children"].
168 |   # repl.rlwrap = false
169 |
170 |   # Packages to load automatically when starting a REPL session
171 |   # without an `.ipkg` file in scope. This defaults to "none".
172 |   # Note: Uncomment only one of the following examples:
173 |   # repl.autoload   = "installed"
174 |   # repl.autoload   = "autolibs"
175 |   # repl.autoload   = [ "sop", "toml" ]
176 |
177 |   # Override this to use a custom Git repo for the Idris compiler
178 |   # url = "https://github.com/idris-lang/Idris2"
179 |
180 |   # Override this to use a custom commit and branch for the Idris compiler
181 |   # commit = "latest:main"
182 |
183 |   # Override this to have a .gitignore file and .git directory
184 |   # created inside of a new pack project upon its creation.
185 |   # git = false
186 |
187 |   # Additional arguments to be passed to the Idris compiler
188 |   # This can be a single string or a list of strings.
189 |   # extra-args = []
190 |
191 |   # Below are some examples for custom packages
192 |
193 |   # A local package to be available with all
194 |   # package collections. The path to the package's root
195 |   # directory can be absolute or relative. In the latter
196 |   # case, it will be considered to be relative to the
197 |   # parent directory of the `pack.toml` file where it is
198 |   # defined.
199 |   #
200 |   # The path to `.ipkg` files must always relative to the
201 |   # given `path`.
202 |   # [custom.all.chem]
203 |   # type = "local"
204 |   # path = "/data/idris/chem"
205 |   # ipkg = "chem.ipkg"
206 |
207 |   # A package as a Git repository to be available with all
208 |   # package collections.
209 |   # [custom.all.foo]
210 |   # type = "git"
211 |   # url  = "https://github.com/bar/foo"
212 |   # commit = "commit-ref"
213 |   # ipkg = "foo.ipkg"
214 |
215 |   # Override library `toml` from package collection `nightly-220503`
216 |   # by using a custom commit hash.
217 |   # [custom.nightly-251023.ilex]
218 |   # type   = "git"
219 |   # url    = "https://github.com/stefan-hoeck/idirs2-ilex"
220 |   # commit = "eb7a146f565276f82ebf30cb6d5502e9f65dcc3c"
221 |   # ipkg   = "ilex.ipkg"
222 |
223 |   # Uncomment and adjust the following entries to specify the
224 |   # default log level associated with each pack command.
225 |   # Possible log levels are:
226 |   #   "debug"
227 |   #   "build"
228 |   #   "info"
229 |   #   "cache"
230 |   #   "warning"
231 |   #   "silence"
232 |   [log]
233 |
234 |   # build             = "build"
235 |   # install-deps      = "build"
236 |   # typecheck         = "build"
237 |   # clean             = "build"
238 |   # cleanbuild        = "build"
239 |   # repl              = "warning"
240 |   # exec              = "warning"
241 |   # install           = "build"
242 |   # install-app       = "build"
243 |   # remove            = "build"
244 |   # remove-app        = "build"
245 |   # run               = "warning"
246 |   # test              = "warning"
247 |   # new               = "build"
248 |   # update            = "build"
249 |   # fetch             = "build"
250 |   # package-path      = "silence"
251 |   # libs-path         = "silence"
252 |   # data-path         = "silence"
253 |   # app-path          = "silence"
254 |   # switch            = "build"
255 |   # update-db         = "build"
256 |   # gc                = "info"
257 |   # info              = "cache"
258 |   # query             = "cache"
259 |   # fuzzy             = "cache"
260 |   # completion        = "silence"
261 |   # completion-script = "silence"
262 |   # uninstall         = "info"
263 |   # help              = "silence"
264 |   """
265 |