1088b5ad3SKyle Evans.\" 2*4d846d26SWarner 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.\" 27088b5ad3SKyle Evans.\" $FreeBSD$ 28088b5ad3SKyle Evans.\" 297ed84fa1SKyle Evans.Dd December 17, 2020 30088b5ad3SKyle Evans.Dt CONFIG.LUA 8 31088b5ad3SKyle Evans.Os 32088b5ad3SKyle Evans.Sh NAME 33088b5ad3SKyle Evans.Nm config.lua 34088b5ad3SKyle Evans.Nd FreeBSD config module 35088b5ad3SKyle Evans.Sh DESCRIPTION 36088b5ad3SKyle Evans.Nm 37088b5ad3SKyle Evanscontains configuration and module loading functionality. 38088b5ad3SKyle Evans.Pp 39088b5ad3SKyle EvansBefore hooking into or using the functionality provided by 40088b5ad3SKyle Evans.Nm , 41088b5ad3SKyle Evansit must be included with a statement such as the following: 42088b5ad3SKyle Evans.Pp 43088b5ad3SKyle Evans.Dl local config = require("config") 44088b5ad3SKyle Evans.Ss Exported functions 45088b5ad3SKyle EvansThe following functions are exported from 46088b5ad3SKyle Evans.Nm : 47088b5ad3SKyle Evans.Bl -tag -width "config.setCarouselIndex(id, idx)" -offset indent 48088b5ad3SKyle Evans.It Fn config.getCarouselIndex id 49088b5ad3SKyle EvansReturns the currently chosen index in the carousel menu entry described by 50088b5ad3SKyle Evans.Ev id . 51088b5ad3SKyle EvansSee the definition of 52088b5ad3SKyle Evans.Xr menu.lua 8 53088b5ad3SKyle Evansfor a more in-depth explanation of carousels. 54088b5ad3SKyle Evans.It Fn config.setCarouselIndex id idx 55088b5ad3SKyle EvansSet the chosen index for the carousel menu entry described by 56088b5ad3SKyle Evans.Ev id 57088b5ad3SKyle Evansto 58088b5ad3SKyle Evans.Ev idx . 59088b5ad3SKyle EvansA lookup will be done as needed to determine what value 60088b5ad3SKyle Evans.Ev idx 61088b5ad3SKyle Evansactually corresponds to. 623fe0ac6aSKyle Evans.It Fn config.readConf file loaded_files 637a5c6c8bSKyle EvansProcess 643fe0ac6aSKyle Evans.Pa file 653fe0ac6aSKyle Evansas a configuration file 663fe0ac6aSKyle Evans.Po e.g., as 673fe0ac6aSKyle Evans.Pa loader.conf 683fe0ac6aSKyle Evans.Pc 693fe0ac6aSKyle Evansand then processing files listed in 703fe0ac6aSKyle Evans.Ev loader_conf_files 713fe0ac6aSKyle Evansvariable 723fe0ac6aSKyle Evans.Po see 733fe0ac6aSKyle Evans.Xr loader.conf 5 743fe0ac6aSKyle Evans.Pc . 753fe0ac6aSKyle EvansThe caller may optionally pass in a table as the 767a5c6c8bSKyle Evans.Ev loaded_files 773fe0ac6aSKyle Evansargument, which uses filenames as keys and any non-nil value to 783fe0ac6aSKyle Evansindicate that the file named by the key has already been loaded and 793fe0ac6aSKyle Evansshould not be loaded again. 80088b5ad3SKyle Evans.It Fn config.processFile name silent 81088b5ad3SKyle EvansProcess and parse 82088b5ad3SKyle Evans.Ev name 83088b5ad3SKyle Evansas a configuration file. 84088b5ad3SKyle EvansReturns true if 85088b5ad3SKyle Evans.Ev name 86088b5ad3SKyle Evansexists and parses without error, false otherwise. 87088b5ad3SKyle EvansIf 88088b5ad3SKyle Evans.Ev silent 89088b5ad3SKyle Evansis true, 90088b5ad3SKyle Evans.Fn config.processFile 91088b5ad3SKyle Evanswill not consider a failure to read the file as a failure. 92088b5ad3SKyle Evans.It Fn config.parse text 93088b5ad3SKyle EvansParse 94088b5ad3SKyle Evans.Ev text 95088b5ad3SKyle Evansas a configuration file. 96088b5ad3SKyle EvansThis is used internally by 97088b5ad3SKyle Evans.Fn config.processFile 98088b5ad3SKyle Evansto parse the contents of a configuration file. 99088b5ad3SKyle EvansReturns true if parsing succeeds without error, false if an error occurred. 100088b5ad3SKyle EvansA message is also printed to the console if an error is encountered. 101088b5ad3SKyle Evans.It Fn config.loadKernel other_kernel 102088b5ad3SKyle EvansAttempts to load 103088b5ad3SKyle Evans.Ev other_kernel 104088b5ad3SKyle Evansas a kernel. 105088b5ad3SKyle EvansIf 106088b5ad3SKyle Evans.Ev other_kernel 107088b5ad3SKyle Evansis unset 108088b5ad3SKyle Evans.Fn config.loadKernel 109088b5ad3SKyle Evanswill attempt to load 110088b5ad3SKyle Evans.Dq kernel . 111088b5ad3SKyle EvansOtherwise, it will try to load 112088b5ad3SKyle Evans.Dq kernel 113088b5ad3SKyle Evansfirst from 114088b5ad3SKyle Evans.Pa /boot/{other_kernel} , 115088b5ad3SKyle Evansthen from 116088b5ad3SKyle Evans.Pa {other_kernel} . 117088b5ad3SKyle Evans.Pp 118088b5ad3SKyle EvansThe latter is tried in case an absolute path has been specified to the kernel 119088b5ad3SKyle Evansto use. 120088b5ad3SKyle Evans.Ev module_path 121088b5ad3SKyle Evansis amended to include the directory the kernel was found in if either of these 122088b5ad3SKyle Evanspaths result in a loaded kernel. 123088b5ad3SKyle Evans.Pp 124088b5ad3SKyle EvansIf no kernel was loaded from either of these paths, 125088b5ad3SKyle Evans.Fn config.loadKernel 126088b5ad3SKyle Evanswill attempt to load a kernel named 127088b5ad3SKyle Evans.Dq {other_kernel} 128088b5ad3SKyle Evansfrom 129088b5ad3SKyle Evans.Ev module_path 130088b5ad3SKyle Evansinstead of attempting to load a kernel named 131088b5ad3SKyle Evans.Dq kernel . 132088b5ad3SKyle Evans.Pp 133088b5ad3SKyle EvansReturns true if a kernel was loaded, false if no kernel was loaded. 134088b5ad3SKyle Evans.It Fn config.selectKernel kernel 135088b5ad3SKyle EvansSet 136088b5ad3SKyle Evans.Ev kernel 137088b5ad3SKyle Evansto the kernel that will be loaded when either 138088b5ad3SKyle Evans.Ic autoboot 139088b5ad3SKyle Evansor 140088b5ad3SKyle Evans.Ic boot 141088b5ad3SKyle Evansare invoked. 142088b5ad3SKyle EvansThis is usually called by the menu system as the kernel selector carousel is 143088b5ad3SKyle Evanstoggled through. 144088b5ad3SKyle Evans.It Fn config.load file reload 145088b5ad3SKyle EvansLoads 146088b5ad3SKyle Evans.Ev file 147088b5ad3SKyle Evansas a configuration file. 148088b5ad3SKyle EvansIf 149088b5ad3SKyle Evans.Ev file 150088b5ad3SKyle Evansis not specified, 151088b5ad3SKyle Evans.Pa /boot/defaults/loader.conf 152088b5ad3SKyle Evansis used. 153088b5ad3SKyle Evans.Fn config.load 154088b5ad3SKyle Evanswill then silently attempt to process any files specified in 155088b5ad3SKyle Evans.Ev loader_conf_files 156088b5ad3SKyle Evansafter 157088b5ad3SKyle Evans.Ev file 158088b5ad3SKyle Evanshas been processed. 159088b5ad3SKyle Evans.Xr nextboot 8 160088b5ad3SKyle Evansconfiguration will also be checked as part of 161088b5ad3SKyle Evans.Fn config.load . 162088b5ad3SKyle EvansBefore returning, all 163088b5ad3SKyle Evans.Dq config.loaded 164088b5ad3SKyle Evanshooks will be run if 165088b5ad3SKyle Evans.Ev reload 166088b5ad3SKyle Evansis not set to true. 167088b5ad3SKyle Evans.It Fn config.reload file 168088b5ad3SKyle EvansReloads 169088b5ad3SKyle Evans.Ev file 170088b5ad3SKyle Evansas a configuration file. 171088b5ad3SKyle Evans.Fn config.reload 172088b5ad3SKyle Evanswill restore the environment to how it existed before the last config was 173088b5ad3SKyle Evansloaded, then it will invoke 174088b5ad3SKyle Evans.Fn config.load file . 175088b5ad3SKyle EvansBefore returning, all 176088b5ad3SKyle Evans.Dq config.reloaded 177088b5ad3SKyle Evanshooks will be run. 178088b5ad3SKyle Evans.It Fn config.loadelf 179088b5ad3SKyle EvansLoads all ELF objects, the selected kernel as well as any modules configured to 180088b5ad3SKyle Evansbe preloaded in 181088b5ad3SKyle Evans.Xr loader.conf 5 . 182088b5ad3SKyle EvansThis will be called by the Lua intercepted 183088b5ad3SKyle Evans.Ic autoboot 184088b5ad3SKyle Evansand 185088b5ad3SKyle Evans.Ic boot 186088b5ad3SKyle Evanscommands. 1874634bb1fSKyle Evans.It Fn config.enableModule modname 1884634bb1fSKyle EvansMarks a module named 1894634bb1fSKyle Evans.Fa modname 1904634bb1fSKyle Evansto be loaded during 1914634bb1fSKyle Evans.Fn config.loadelf . 1924634bb1fSKyle EvansIf the module was previously blacklisted, then it will be forcefully allowed to 1934634bb1fSKyle Evansload. 1944634bb1fSKyle Evans.It Fn config.disableModule modname 1954634bb1fSKyle EvansMarks a module named 1964634bb1fSKyle Evans.Fa modname 1974634bb1fSKyle Evansto not be loaded during 1984634bb1fSKyle Evans.Fn config.loadelf . 1994634bb1fSKyle Evans.It Fn config.isModuleEnabled modname 2004634bb1fSKyle EvansChecks if the module named 2014634bb1fSKyle Evans.Fa modname 2024634bb1fSKyle Evanswill be loaded during 2034634bb1fSKyle Evans.Fn config.loadelf . 2044634bb1fSKyle EvansIt checks both that the module is marked for loading and that it is either 2054634bb1fSKyle Evansforced or not blacklisted. 2067ed84fa1SKyle Evans.It Fn config.getModuleInfo 2077ed84fa1SKyle EvansReturns a table with 2087ed84fa1SKyle Evans.Dq modules 2097ed84fa1SKyle Evansand 2107ed84fa1SKyle Evans.Dq blacklist 2117ed84fa1SKyle Evanstables describing the modules that the config module has been made aware of via 2127ed84fa1SKyle Evans.Xr loader.conf 5 2137ed84fa1SKyle Evansas well as a representation of 2147ed84fa1SKyle Evans.Ar module_blacklist . 215088b5ad3SKyle Evans.El 216088b5ad3SKyle Evans.Ss Defined Hooks 217088b5ad3SKyle EvansThe following hooks are defined in 218088b5ad3SKyle Evans.Nm : 219088b5ad3SKyle Evans.Bl -tag -width "config.reloaded" -offset indent 2203cb2f5f3SKyle Evans.It Fn config.buildenv env 22160a2823cSKyle Evans.It Fn config.loaded 22260a2823cSKyle Evans.It Fn config.reloaded 22360a2823cSKyle Evans.It Fn kernel.loaded 22460a2823cSKyle Evans.It Fn modules.loaded 225088b5ad3SKyle Evans.El 2263cb2f5f3SKyle Evans.Pp 2273cb2f5f3SKyle EvansNote that the 2283cb2f5f3SKyle Evans.Fn config.buildenv 2293cb2f5f3SKyle Evanshook is only invoked when an environment needs to be built to execute a lua 2303cb2f5f3SKyle Evansconfiguration file that has been specified in 2313cb2f5f3SKyle Evans.Ev loader_conf_files . 2323cb2f5f3SKyle EvansIt will be invoked for each configuration file encountered. 233088b5ad3SKyle Evans.Sh SEE ALSO 234088b5ad3SKyle Evans.Xr loader.conf 5 , 235088b5ad3SKyle Evans.Xr loader 8 , 236088b5ad3SKyle Evans.Xr menu.lua 8 , 237088b5ad3SKyle Evans.Xr nextboot 8 238088b5ad3SKyle Evans.Sh AUTHORS 239088b5ad3SKyle EvansThe 240088b5ad3SKyle Evans.Nm 241088b5ad3SKyle Evansfile was originally written by 242088b5ad3SKyle Evans.An Pedro Souza Aq Mt pedrosouza@FreeBSD.org . 243088b5ad3SKyle EvansLater work and this manual page was done by 244088b5ad3SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 245