xref: /freebsd/stand/lua/config.lua.8 (revision c475e61f66fe8fe939e18ec7821c2340569f3271)
1088b5ad3SKyle Evans.\"
24d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause
3088b5ad3SKyle Evans.\"
4088b5ad3SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
5088b5ad3SKyle Evans.\"
6088b5ad3SKyle Evans.\" Redistribution and use in source and binary forms, with or without
7088b5ad3SKyle Evans.\" modification, are permitted provided that the following conditions
8088b5ad3SKyle Evans.\" are met:
9088b5ad3SKyle Evans.\" 1. Redistributions of source code must retain the above copyright
10088b5ad3SKyle Evans.\"    notice, this list of conditions and the following disclaimer.
11088b5ad3SKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright
12088b5ad3SKyle Evans.\"    notice, this list of conditions and the following disclaimer in the
13088b5ad3SKyle Evans.\"    documentation and/or other materials provided with the distribution.
14088b5ad3SKyle Evans.\"
15088b5ad3SKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16088b5ad3SKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17088b5ad3SKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18088b5ad3SKyle Evans.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19088b5ad3SKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20088b5ad3SKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21088b5ad3SKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22088b5ad3SKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23088b5ad3SKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24088b5ad3SKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25088b5ad3SKyle Evans.\" SUCH DAMAGE.
26088b5ad3SKyle Evans.\"
277ed84fa1SKyle Evans.Dd December 17, 2020
28088b5ad3SKyle Evans.Dt CONFIG.LUA 8
29088b5ad3SKyle Evans.Os
30088b5ad3SKyle Evans.Sh NAME
31088b5ad3SKyle Evans.Nm config.lua
32088b5ad3SKyle Evans.Nd FreeBSD config module
33088b5ad3SKyle Evans.Sh DESCRIPTION
34088b5ad3SKyle Evans.Nm
35088b5ad3SKyle Evanscontains configuration and module loading functionality.
36088b5ad3SKyle Evans.Pp
37088b5ad3SKyle EvansBefore hooking into or using the functionality provided by
38088b5ad3SKyle Evans.Nm ,
39088b5ad3SKyle Evansit must be included with a statement such as the following:
40088b5ad3SKyle Evans.Pp
41088b5ad3SKyle Evans.Dl local config = require("config")
42088b5ad3SKyle Evans.Ss Exported functions
43088b5ad3SKyle EvansThe following functions are exported from
44088b5ad3SKyle Evans.Nm :
45088b5ad3SKyle Evans.Bl -tag -width "config.setCarouselIndex(id, idx)" -offset indent
46088b5ad3SKyle Evans.It Fn config.getCarouselIndex id
47088b5ad3SKyle EvansReturns the currently chosen index in the carousel menu entry described by
48088b5ad3SKyle Evans.Ev id .
49088b5ad3SKyle EvansSee the definition of
50088b5ad3SKyle Evans.Xr menu.lua 8
51088b5ad3SKyle Evansfor a more in-depth explanation of carousels.
52088b5ad3SKyle Evans.It Fn config.setCarouselIndex id idx
53088b5ad3SKyle EvansSet the chosen index for the carousel menu entry described by
54088b5ad3SKyle Evans.Ev id
55088b5ad3SKyle Evansto
56088b5ad3SKyle Evans.Ev idx .
57088b5ad3SKyle EvansA lookup will be done as needed to determine what value
58088b5ad3SKyle Evans.Ev idx
59088b5ad3SKyle Evansactually corresponds to.
603fe0ac6aSKyle Evans.It Fn config.readConf file loaded_files
617a5c6c8bSKyle EvansProcess
623fe0ac6aSKyle Evans.Pa file
633fe0ac6aSKyle Evansas a configuration file
643fe0ac6aSKyle Evans.Po e.g., as
653fe0ac6aSKyle Evans.Pa loader.conf
663fe0ac6aSKyle Evans.Pc
67*c475e61fSStéphane Rochoyand then process files listed in the
683fe0ac6aSKyle Evans.Ev loader_conf_files
69*c475e61fSStéphane Rochoyvariable. Additionnaly, the top-level call to readConf will process files listed in the
70*c475e61fSStéphane Rochoy.Ev loader_conf_dirs
71*c475e61fSStéphane Rochoyand
72*c475e61fSStéphane Rochoy.Ev local_loader_conf_files
73*c475e61fSStéphane Rochoyvariables
743fe0ac6aSKyle Evans.Po see
753fe0ac6aSKyle Evans.Xr loader.conf 5
763fe0ac6aSKyle Evans.Pc .
773fe0ac6aSKyle EvansThe caller may optionally pass in a table as the
787a5c6c8bSKyle Evans.Ev loaded_files
793fe0ac6aSKyle Evansargument, which uses filenames as keys and any non-nil value to
803fe0ac6aSKyle Evansindicate that the file named by the key has already been loaded and
813fe0ac6aSKyle Evansshould not be loaded again.
82088b5ad3SKyle Evans.It Fn config.processFile name silent
83088b5ad3SKyle EvansProcess and parse
84088b5ad3SKyle Evans.Ev name
85088b5ad3SKyle Evansas a configuration file.
86088b5ad3SKyle EvansReturns true if
87088b5ad3SKyle Evans.Ev name
88088b5ad3SKyle Evansexists and parses without error, false otherwise.
89088b5ad3SKyle EvansIf
90088b5ad3SKyle Evans.Ev silent
91088b5ad3SKyle Evansis true,
92088b5ad3SKyle Evans.Fn config.processFile
93088b5ad3SKyle Evanswill not consider a failure to read the file as a failure.
94088b5ad3SKyle Evans.It Fn config.parse text
95088b5ad3SKyle EvansParse
96088b5ad3SKyle Evans.Ev text
97088b5ad3SKyle Evansas a configuration file.
98088b5ad3SKyle EvansThis is used internally by
99088b5ad3SKyle Evans.Fn config.processFile
100088b5ad3SKyle Evansto parse the contents of a configuration file.
101088b5ad3SKyle EvansReturns true if parsing succeeds without error, false if an error occurred.
102088b5ad3SKyle EvansA message is also printed to the console if an error is encountered.
103088b5ad3SKyle Evans.It Fn config.loadKernel other_kernel
104088b5ad3SKyle EvansAttempts to load
105088b5ad3SKyle Evans.Ev other_kernel
106088b5ad3SKyle Evansas a kernel.
107088b5ad3SKyle EvansIf
108088b5ad3SKyle Evans.Ev other_kernel
109088b5ad3SKyle Evansis unset
110088b5ad3SKyle Evans.Fn config.loadKernel
111088b5ad3SKyle Evanswill attempt to load
112088b5ad3SKyle Evans.Dq kernel .
113088b5ad3SKyle EvansOtherwise, it will try to load
114088b5ad3SKyle Evans.Dq kernel
115088b5ad3SKyle Evansfirst from
116088b5ad3SKyle Evans.Pa /boot/{other_kernel} ,
117088b5ad3SKyle Evansthen from
118088b5ad3SKyle Evans.Pa {other_kernel} .
119088b5ad3SKyle Evans.Pp
120088b5ad3SKyle EvansThe latter is tried in case an absolute path has been specified to the kernel
121088b5ad3SKyle Evansto use.
122088b5ad3SKyle Evans.Ev module_path
123088b5ad3SKyle Evansis amended to include the directory the kernel was found in if either of these
124088b5ad3SKyle Evanspaths result in a loaded kernel.
125088b5ad3SKyle Evans.Pp
126088b5ad3SKyle EvansIf no kernel was loaded from either of these paths,
127088b5ad3SKyle Evans.Fn config.loadKernel
128088b5ad3SKyle Evanswill attempt to load a kernel named
129088b5ad3SKyle Evans.Dq {other_kernel}
130088b5ad3SKyle Evansfrom
131088b5ad3SKyle Evans.Ev module_path
132088b5ad3SKyle Evansinstead of attempting to load a kernel named
133088b5ad3SKyle Evans.Dq kernel .
134088b5ad3SKyle Evans.Pp
135088b5ad3SKyle EvansReturns true if a kernel was loaded, false if no kernel was loaded.
136088b5ad3SKyle Evans.It Fn config.selectKernel kernel
137088b5ad3SKyle EvansSet
138088b5ad3SKyle Evans.Ev kernel
139088b5ad3SKyle Evansto the kernel that will be loaded when either
140088b5ad3SKyle Evans.Ic autoboot
141088b5ad3SKyle Evansor
142088b5ad3SKyle Evans.Ic boot
143088b5ad3SKyle Evansare invoked.
144088b5ad3SKyle EvansThis is usually called by the menu system as the kernel selector carousel is
145088b5ad3SKyle Evanstoggled through.
146088b5ad3SKyle Evans.It Fn config.load file reload
147088b5ad3SKyle EvansLoads
148088b5ad3SKyle Evans.Ev file
149088b5ad3SKyle Evansas a configuration file.
150088b5ad3SKyle EvansIf
151088b5ad3SKyle Evans.Ev file
152088b5ad3SKyle Evansis not specified,
153088b5ad3SKyle Evans.Pa /boot/defaults/loader.conf
154088b5ad3SKyle Evansis used.
155088b5ad3SKyle Evans.Fn config.load
156088b5ad3SKyle Evanswill then silently attempt to process any files specified in
157088b5ad3SKyle Evans.Ev loader_conf_files
158088b5ad3SKyle Evansafter
159088b5ad3SKyle Evans.Ev file
160088b5ad3SKyle Evanshas been processed.
161088b5ad3SKyle Evans.Xr nextboot 8
162088b5ad3SKyle Evansconfiguration will also be checked as part of
163088b5ad3SKyle Evans.Fn config.load .
164088b5ad3SKyle EvansBefore returning, all
165088b5ad3SKyle Evans.Dq config.loaded
166088b5ad3SKyle Evanshooks will be run if
167088b5ad3SKyle Evans.Ev reload
168088b5ad3SKyle Evansis not set to true.
169088b5ad3SKyle Evans.It Fn config.reload file
170088b5ad3SKyle EvansReloads
171088b5ad3SKyle Evans.Ev file
172088b5ad3SKyle Evansas a configuration file.
173088b5ad3SKyle Evans.Fn config.reload
174088b5ad3SKyle Evanswill restore the environment to how it existed before the last config was
175088b5ad3SKyle Evansloaded, then it will invoke
176088b5ad3SKyle Evans.Fn config.load file .
177088b5ad3SKyle EvansBefore returning, all
178088b5ad3SKyle Evans.Dq config.reloaded
179088b5ad3SKyle Evanshooks will be run.
180088b5ad3SKyle Evans.It Fn config.loadelf
181088b5ad3SKyle EvansLoads all ELF objects, the selected kernel as well as any modules configured to
182088b5ad3SKyle Evansbe preloaded in
183088b5ad3SKyle Evans.Xr loader.conf 5 .
184088b5ad3SKyle EvansThis will be called by the Lua intercepted
185088b5ad3SKyle Evans.Ic autoboot
186088b5ad3SKyle Evansand
187088b5ad3SKyle Evans.Ic boot
188088b5ad3SKyle Evanscommands.
1894634bb1fSKyle Evans.It Fn config.enableModule modname
1904634bb1fSKyle EvansMarks a module named
1914634bb1fSKyle Evans.Fa modname
1924634bb1fSKyle Evansto be loaded during
1934634bb1fSKyle Evans.Fn config.loadelf .
1944634bb1fSKyle EvansIf the module was previously blacklisted, then it will be forcefully allowed to
1954634bb1fSKyle Evansload.
1964634bb1fSKyle Evans.It Fn config.disableModule modname
1974634bb1fSKyle EvansMarks a module named
1984634bb1fSKyle Evans.Fa modname
1994634bb1fSKyle Evansto not be loaded during
2004634bb1fSKyle Evans.Fn config.loadelf .
2014634bb1fSKyle Evans.It Fn config.isModuleEnabled modname
2024634bb1fSKyle EvansChecks if the module named
2034634bb1fSKyle Evans.Fa modname
2044634bb1fSKyle Evanswill be loaded during
2054634bb1fSKyle Evans.Fn config.loadelf .
2064634bb1fSKyle EvansIt checks both that the module is marked for loading and that it is either
2074634bb1fSKyle Evansforced or not blacklisted.
2087ed84fa1SKyle Evans.It Fn config.getModuleInfo
2097ed84fa1SKyle EvansReturns a table with
2107ed84fa1SKyle Evans.Dq modules
2117ed84fa1SKyle Evansand
2127ed84fa1SKyle Evans.Dq blacklist
2137ed84fa1SKyle Evanstables describing the modules that the config module has been made aware of via
2147ed84fa1SKyle Evans.Xr loader.conf 5
2157ed84fa1SKyle Evansas well as a representation of
2167ed84fa1SKyle Evans.Ar module_blacklist .
217088b5ad3SKyle Evans.El
218088b5ad3SKyle Evans.Ss Defined Hooks
219088b5ad3SKyle EvansThe following hooks are defined in
220088b5ad3SKyle Evans.Nm :
221088b5ad3SKyle Evans.Bl -tag -width "config.reloaded" -offset indent
2223cb2f5f3SKyle Evans.It Fn config.buildenv env
22360a2823cSKyle Evans.It Fn config.loaded
22460a2823cSKyle Evans.It Fn config.reloaded
22560a2823cSKyle Evans.It Fn kernel.loaded
22660a2823cSKyle Evans.It Fn modules.loaded
227088b5ad3SKyle Evans.El
2283cb2f5f3SKyle Evans.Pp
2293cb2f5f3SKyle EvansNote that the
2303cb2f5f3SKyle Evans.Fn config.buildenv
2313cb2f5f3SKyle Evanshook is only invoked when an environment needs to be built to execute a lua
2323cb2f5f3SKyle Evansconfiguration file that has been specified in
2333cb2f5f3SKyle Evans.Ev loader_conf_files .
2343cb2f5f3SKyle EvansIt will be invoked for each configuration file encountered.
235088b5ad3SKyle Evans.Sh SEE ALSO
236088b5ad3SKyle Evans.Xr loader.conf 5 ,
237088b5ad3SKyle Evans.Xr loader 8 ,
238088b5ad3SKyle Evans.Xr menu.lua 8 ,
239088b5ad3SKyle Evans.Xr nextboot 8
240088b5ad3SKyle Evans.Sh AUTHORS
241088b5ad3SKyle EvansThe
242088b5ad3SKyle Evans.Nm
243088b5ad3SKyle Evansfile was originally written by
244088b5ad3SKyle Evans.An Pedro Souza Aq Mt pedrosouza@FreeBSD.org .
245088b5ad3SKyle EvansLater work and this manual page was done by
246088b5ad3SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org .
247