0 | module Pack.Config.Environment.Variable
 1 |
 2 | import public Data.FilePath.File
 3 | import Pack.Config.Types
 4 |
 5 | --------------------------------------------------------------------------------
 6 | ---         Types
 7 | --------------------------------------------------------------------------------
 8 |
 9 | public export %inline
10 | 0 DirList : Type
11 | DirList = List (Path Abs)
12 |
13 | export
14 | data EnvVar : Type where
15 |   MkEnvVar : (name : String) -> (value : String) -> EnvVar
16 |
17 | %inline
18 | envVar : Interpolation a => (name : String) -> (val : a) -> EnvVar
19 | envVar name = MkEnvVar name . interpolate
20 |
21 | --------------------------------------------------------------------------------
22 | ---         Interpolation
23 | --------------------------------------------------------------------------------
24 |
25 | ||| Interpolate a list of directories as a colon-separated string
26 | export
27 | Interpolation DirList where
28 |   interpolate = fastConcat . intersperse ":" . map interpolate
29 |
30 | ||| Interpolate an environment variable for use in a shell
31 | export
32 | Interpolation EnvVar where
33 |   interpolate (MkEnvVar var val) = "\{var}=\{val}"
34 |
35 | --------------------------------------------------------------------------------
36 | --          Environment Variables
37 | --------------------------------------------------------------------------------
38 |
39 | -- The official documentation for Idris 2 compiler environment variables:
40 | -- https://github.com/idris-lang/Idris2/blob/main/docs/source/reference/envvars.rst
41 |
42 | ||| Code generation backend used by the Idris 2 compiler
43 | export %inline
44 | IdrisCodegenVar : Codegen -> EnvVar
45 | IdrisCodegenVar = envVar "IDRIS2_CG"
46 |
47 | ||| Path to the Scheme executable used by the Scheme backend
48 | export %inline
49 | SchemeVar : FilePath -> EnvVar
50 | SchemeVar = envVar "SCHEME"
51 |
52 | ||| Path to the Idris 2 boot file, used by Idris 2 Makefile
53 | export %inline
54 | IdrisBootVar : File Abs -> EnvVar
55 | IdrisBootVar = envVar "IDRIS2_BOOT"
56 |
57 | ||| Installation prefix for Idris 2
58 | export %inline
59 | PrefixVar : Path Abs -> EnvVar
60 | PrefixVar = envVar "PREFIX"
61 |
62 | ||| Alternative way to set the Idris 2 installation prefix
63 | export %inline
64 | IdrisPrefixVar : Path Abs -> EnvVar
65 | IdrisPrefixVar = envVar "IDRIS2_PREFIX"
66 |
67 | ||| Directories where Idris 2 searches for package definitions,
68 | ||| in addition to the default locations
69 | export %inline
70 | IdrisPackagePathVar : DirList -> EnvVar
71 | IdrisPackagePathVar = envVar "IDRIS2_PACKAGE_PATH"
72 |
73 | ||| Directories where Idris 2 looks for data files, typically
74 | ||| support code for code generators
75 | export %inline
76 | IdrisDataVar : DirList -> EnvVar
77 | IdrisDataVar = envVar "IDRIS2_DATA"
78 |
79 | ||| Directories where Idris 2 searches for libraries used by code generators
80 | export %inline
81 | IdrisLibsVar : DirList -> EnvVar
82 | IdrisLibsVar = envVar "IDRIS2_LIBS"
83 |