30 lines
No EOL
1.4 KiB
Nix
30 lines
No EOL
1.4 KiB
Nix
let
|
|
lib = import <nixpkgs/lib>;
|
|
|
|
validateFile = siteName: index: file:
|
|
let
|
|
_ = if builtins.isAttrs file then null else throw "web.${siteName}.files[${toString index}] must be an attrset.";
|
|
__ = if file ? path && builtins.isString file.path then null else throw "web.${siteName}.files[${toString index}].path must be a string.";
|
|
___ = if file ? content && builtins.isString file.content then null else throw "web.${siteName}.files[${toString index}].content must be a string.";
|
|
____ = if file ? contentType && builtins.isString file.contentType && file.contentType != "" then null else throw "web.${siteName}.files[${toString index}].contentType must be a non-empty string.";
|
|
_____ = if file ? status && builtins.isInt file.status then null else throw "web.${siteName}.files[${toString index}].status must be an int.";
|
|
in
|
|
file;
|
|
|
|
validateSite = siteName: site:
|
|
let
|
|
_ = if builtins.isAttrs site then null else throw "web.${siteName} must be an attrset.";
|
|
__ = if site ? files && builtins.isList site.files then null else throw "web.${siteName}.files must be a list.";
|
|
___ = lib.imap0 (index: file: validateFile siteName index file) site.files;
|
|
in
|
|
site;
|
|
|
|
getWebConfig = webConfig:
|
|
if builtins.isAttrs webConfig then
|
|
lib.mapAttrs validateSite webConfig
|
|
else
|
|
throw "config/web.nix must evaluate to an attrset.";
|
|
in
|
|
{
|
|
inherit getWebConfig;
|
|
} |