feat: add initial config
This commit is contained in:
commit
fb98563bb6
26 changed files with 576 additions and 0 deletions
30
validation/web.nix
Normal file
30
validation/web.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue