nixite/nixite/builder.nix
2024-01-04 05:23:06 +00:00

27 lines
808 B
Nix

rec {
buildSiteTo = prefix: site:
builtins.toString (builtins.attrValues (builtins.mapAttrs (name: content:
if builtins.isString content
then ''
cp ${builtins.toFile name content} ${prefix}/${name}
''
else if builtins.isPath content
then ''
cp -r ${content} ${prefix}/${name}
''
else if builtins.isAttrs content && content ? "__toString"
then ''
cp ${builtins.toFile name (toString content)} ${prefix}/${name}
''
else if builtins.isAttrs content
then ''
mkdir -p ${prefix}/${name}
${buildSiteTo "${prefix}/${name}" content}
''
else
throw "Site page must be string, path or attrset, but got ${
builtins.typeOf content
}: [${toString content}]")
site));
}