jail.nix/lib/combinators.nix
Alex David 7acd363b6d Implement combinator aliases
To make it easier to rename combinators without breaking anyone's
configuration, this change allows combinators to specify a list of
`aliases` that are also exported from `jail.combinators`.

The aliases are also documented on the documentation website.
2026-04-02 12:59:14 -07:00

43 lines
1,016 B
Nix

pkgs: jail:
let
inherit (pkgs) lib;
helpers = import ./helpers.nix pkgs;
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;
}