commit 781417bcd1a223310370b274a15f0f39f721d96e
parent 31382d9d956e8bb4d57535c4c373a78b67beeaf4
Author: figsoda <figsoda@pm.me>
Date: Wed, 5 Apr 2023 10:59:43 -0400
parent 31382d9d956e8bb4d57535c4c373a78b67beeaf4
Author: figsoda <figsoda@pm.me>
Date: Wed, 5 Apr 2023 10:59:43 -0400
load: add transformer option
2 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md @@ -22,7 +22,7 @@ A list of available versions can be found on the ### [`load`](src/load.nix) -Type: `{ src, loader?, inputs? } -> { ... }` +Type: `{ src, loader?, inputs?, transformer? } -> { ... }` Arguments: @@ -41,6 +41,11 @@ Arguments: `self`, `super`, and `root` are reserved names that cannot be passed as an input. To work around that, remove them using `removeAttrs`, or pass them by overriding the loader. +- (optional) `transformer` : `{ ... } -> a` + + Module transformer, defaults to `id` (no transformation). + This will transform each directory module in `src`, including the root. + The main entry point of haumea. This is probably the function you are looking for. Nix files found in `src` are loaded into an attribute set with the specified `loader`.
diff --git a/src/load.nix b/src/load.nix @@ -17,6 +17,7 @@ let flip getAttrFromPath hasSuffix + id nameValuePair optionalAttrs pipe @@ -40,21 +41,22 @@ let entry = { isDir, path, ... }: "${if isDir then "directory" else "file"} '${path}'"; - view = { cursor ? [ ], node, pov }: + view = { cursor ? [ ], node, pov, transformer }: if node.isDir then - flip concatMapAttrs node.children - (name: node: optionalAttrs - { - public = true; - root = pov != "external"; - super = pov != "external" && take (length cursor) pov == cursor; - }.${node.visibility} - { - ${name} = view { - cursor = cursor ++ [ name ]; - inherit node pov; - }; - }) + transformer + (flip concatMapAttrs node.children + (name: node: optionalAttrs + { + public = true; + root = pov != "external"; + super = pov != "external" && take (length cursor) pov == cursor; + }.${node.visibility} + { + ${name} = view { + cursor = cursor ++ [ name ]; + inherit node pov transformer; + }; + })) else node.content; @@ -116,7 +118,11 @@ let ]; in -{ src, loader ? root.loaders.default, inputs ? { } }: +{ src +, loader ? root.loaders.default +, inputs ? { } +, transformer ? id +}: assert all (name: inputs ? ${name} @@ -124,13 +130,14 @@ assert all [ "self" "super" "root" ]; view { + inherit transformer; pov = "external"; node = fix (node: { isDir = true; children = aggregate { inherit src loader inputs; tree = { - inherit node; + inherit node transformer; pov = [ ]; }; };