jail.nix/lib/combinators.nix

53 lines
1.3 KiB
Nix
Raw Permalink Normal View History

{
pkgs,
suppressExperimentalWarnings ? false,
...
}:
jail:
2025-09-11 07:31:48 -07:00
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: combinator:
if lib.length names == 0 then
acc
else
let
name = lib.head names;
combinatorImpl =
if combinator.experimental or false && !suppressExperimentalWarnings then
builtins.warn "jail.nix combinator ${name} is experimental!" combinator.impl
else
combinator.impl;
in
if acc ? ${name} then
throw "duplicate combinator ${name}"
else
foldCombinator (acc // { ${name} = combinatorImpl; }) (lib.tail names) combinator;
in
lib.foldl' (acc: { name, value }: foldCombinator acc ([ name ] ++ value.aliases or [ ]) value) { } (
lib.attrsToList rawCombinators
);
in
{
inherit combinators;
docs = rawCombinators;
2025-04-27 12:07:03 -07:00
}