57 lines
No EOL
1.8 KiB
Nix
57 lines
No EOL
1.8 KiB
Nix
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;
|
|
} |