fix: init can be build from config

dev
LeMarsu 2026-03-11 21:02:09 +01:00
parent aff1dbc079
commit 2816b256d4
1 changed files with 53 additions and 3 deletions

View File

@ -1,6 +1,56 @@
{pkgs, ...}: let
{
pkgs,
callModule,
...
}: let
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
fix (self: {
module = types.submodule {
@ -46,6 +96,6 @@ in
else if isPath init
then readFile init
else if isAttrs init
then "print('not implmented yet')"
then buildInit init
else null;
})