jail.nix/lib/combinators.nix

43 lines
1,016 B
Nix
Raw Normal View History

2025-09-11 07:31:48 -07:00
pkgs: jail:
let
2025-08-07 15:29:16 -07:00
inherit (pkgs) lib;
helpers = import ./helpers.nix pkgs;
2025-04-27 12:07:03 -07:00
rawCombinators = lib.mapAttrs' (
fileName: _:
lib.nameValuePair (lib.removeSuffix ".nix" fileName) (
import ./combinators/${fileName} {
inherit
combinators
helpers
jail
lib
pkgs
;
}
)
) (builtins.readDir ./combinators);
combinators =
let
foldCombinator =
acc: names: combinatorImpl:
if lib.length names == 0 then
acc
else
let
name = lib.head names;
in
if acc ? ${name} then
throw "duplicate combinator ${name}"
else
foldCombinator (acc // { ${name} = combinatorImpl; }) (lib.tail names) combinatorImpl;
in
lib.foldl' (
acc: { name, value }: foldCombinator acc ([ name ] ++ value.aliases or [ ]) value.impl
) { } (lib.attrsToList rawCombinators);
in
{
inherit combinators;
docs = rawCombinators;
2025-04-27 12:07:03 -07:00
}