fix: init can be build from config
parent
aff1dbc079
commit
2816b256d4
|
|
@ -1,6 +1,56 @@
|
||||||
{pkgs, ...}: let
|
{
|
||||||
|
pkgs,
|
||||||
|
callModule,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
inherit (builtins) isAttrs isPath isString readFile;
|
inherit (builtins) isAttrs isPath isString readFile;
|
||||||
inherit (pkgs.lib) fix mkOption types;
|
inherit
|
||||||
|
(pkgs.lib)
|
||||||
|
fileContents
|
||||||
|
fix
|
||||||
|
mkOption
|
||||||
|
optionalAttrs
|
||||||
|
optionalString
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
lua = callModule ../lua.nix {};
|
||||||
|
|
||||||
|
textOrContent = content:
|
||||||
|
if isPath content
|
||||||
|
then fileContents content
|
||||||
|
else content;
|
||||||
|
|
||||||
|
buildInit = {
|
||||||
|
init ? null,
|
||||||
|
postInit ? null,
|
||||||
|
config ? null,
|
||||||
|
}: let
|
||||||
|
initStr = optionalString (! isNull init) ''
|
||||||
|
(function()
|
||||||
|
${textOrContent init}
|
||||||
|
end)();
|
||||||
|
|
||||||
|
'';
|
||||||
|
|
||||||
|
postInitContent = optionalAttrs (! isNull postInit) {
|
||||||
|
post_init = lua.lambda [] (textOrContent (lua.raw postInit));
|
||||||
|
};
|
||||||
|
|
||||||
|
slothCall = "require('sloth-flake').setup ${lua.renderLua {} postInitContent}";
|
||||||
|
|
||||||
|
configStr = optionalString (! isNull config) ''
|
||||||
|
|
||||||
|
(function()
|
||||||
|
${textOrContent config}
|
||||||
|
end)()
|
||||||
|
'';
|
||||||
|
in ''
|
||||||
|
-- Generated by sloth-flake
|
||||||
|
${initStr}
|
||||||
|
${slothCall}
|
||||||
|
${configStr}
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
fix (self: {
|
fix (self: {
|
||||||
module = types.submodule {
|
module = types.submodule {
|
||||||
|
|
@ -46,6 +96,6 @@ in
|
||||||
else if isPath init
|
else if isPath init
|
||||||
then readFile init
|
then readFile init
|
||||||
else if isAttrs init
|
else if isAttrs init
|
||||||
then "print('not implmented yet')"
|
then buildInit init
|
||||||
else null;
|
else null;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue