feat: try rework
This commit is contained in:
parent
1ddbd3b8b6
commit
ecf10628c3
51 changed files with 1941 additions and 445 deletions
57
validation/storage.nix
Normal file
57
validation/storage.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
let
|
||||
lib = import <nixpkgs/lib>;
|
||||
|
||||
validateStorageEntry = name: entry:
|
||||
let
|
||||
_ =
|
||||
if builtins.isAttrs entry then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' must be an attrset.";
|
||||
__ =
|
||||
if entry ? path && builtins.isString entry.path && entry.path != "" then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' must define path as a non-empty string.";
|
||||
___ =
|
||||
if entry ? source && builtins.isString entry.source && entry.source != "" then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' must define source as a non-empty string.";
|
||||
____ =
|
||||
if entry ? type && builtins.isString entry.type && entry.type != "" then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' must define type as a non-empty string.";
|
||||
_____ =
|
||||
if entry ? options && builtins.isList entry.options then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' must define options as a list.";
|
||||
______ =
|
||||
if lib.all builtins.isString entry.options then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' options must be a list of strings.";
|
||||
_______ =
|
||||
if !(entry ? extra) || builtins.isAttrs entry.extra then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix entry '${name}' field extra must be an attrset when present.";
|
||||
in
|
||||
entry;
|
||||
|
||||
getStorageConfig = config:
|
||||
let
|
||||
_ =
|
||||
if builtins.isAttrs config then
|
||||
null
|
||||
else
|
||||
throw "config/storage.nix must evaluate to an attrset.";
|
||||
__ = lib.mapAttrs validateStorageEntry config;
|
||||
in
|
||||
config;
|
||||
in
|
||||
rec {
|
||||
inherit getStorageConfig validateStorageEntry;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue