support local confgen options

This commit is contained in:
LordMZTE 2023-04-26 10:12:40 +02:00
parent ca3b276b38
commit 2d073e4a66
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -4,10 +4,20 @@ cg.addPath ".ssh"
cg.addPath ".cargo" cg.addPath ".cargo"
cg.addPath "etc" cg.addPath "etc"
for k, v in pairs(require "cg_opts") do -- Recursively merge 2 tables
cg.opt[k] = v local function merge(a, b)
for k, v in pairs(b) do
if type(v) == "table" and type(a[k]) == "table" then
merge(a[k], v)
else
a[k] = v
end
end
return a
end end
cg.opt = merge(cg.opt, require "cg_opts")
-- This function is called in templates to allow adding device-specific configs. -- This function is called in templates to allow adding device-specific configs.
cg.opt.getDeviceConf = function(id) cg.opt.getDeviceConf = function(id)
local path = os.getenv "HOME" .. "/.config/mzte_localconf/" .. id local path = os.getenv "HOME" .. "/.config/mzte_localconf/" .. id
@ -20,6 +30,12 @@ cg.opt.getDeviceConf = function(id)
return file:read "*a" return file:read "*a"
end end
local local_opts = loadfile(os.getenv "HOME" .. "/.config/mzte_localconf/opts.lua")
if local_opts then
cg.opt = merge(cg.opt, local_opts())
end
-- Get the output of a system command -- Get the output of a system command
cg.opt.system = function(cmd) cg.opt.system = function(cmd)
local handle = io.popen(cmd) local handle = io.popen(cmd)