40 lines
No EOL
1 KiB
Nix
40 lines
No EOL
1 KiB
Nix
let
|
|
lib = import <nixpkgs/lib>;
|
|
|
|
ensureStoreName = name:
|
|
if builtins.match "^[A-Za-z_][A-Za-z0-9_-]*$" name != null then
|
|
name
|
|
else
|
|
throw "config/web.nix store name '${name}' is invalid. Use letters, numbers, '_' or '-', starting with a letter or '_' .";
|
|
|
|
validateStore = name: store:
|
|
let
|
|
_ = ensureStoreName name;
|
|
__ =
|
|
if builtins.isAttrs store then
|
|
null
|
|
else
|
|
throw "config/web.nix stores.${name} must be an attrset.";
|
|
___ =
|
|
if store ? root && builtins.isPath store.root then
|
|
null
|
|
else
|
|
throw "config/web.nix stores.${name}.root must be a Nix path.";
|
|
in
|
|
store;
|
|
|
|
getStores = webConfig:
|
|
let
|
|
stores =
|
|
if builtins.isAttrs webConfig && webConfig ? stores && builtins.isAttrs webConfig.stores then
|
|
webConfig.stores
|
|
else
|
|
throw "config/web.nix must define stores as an attrset.";
|
|
|
|
_ = lib.mapAttrs validateStore stores;
|
|
in
|
|
stores;
|
|
in
|
|
rec {
|
|
inherit getStores;
|
|
} |