The `lib/combinators.nix` file was getting quite long and some ideas I have for future combinators may even require ancillary files. To help scale these changes, this commit breaks each combinator into its own file under the `lib/combinators` directory.
44 lines
1 KiB
Nix
44 lines
1 KiB
Nix
{ helpers, lib, ... }:
|
|
{
|
|
sig = "String -> Permission -> Permission";
|
|
doc = ''
|
|
Only run the passed permission if include-once hasn't been previously
|
|
called with the specified key.
|
|
|
|
This is useful when writing your own combinators.
|
|
|
|
```nix
|
|
let
|
|
jail = jail-nix.lib.extend {
|
|
inherit pkgs;
|
|
additionalCombinators = combinators: with combinators; {
|
|
# foo isn't `include-once` so each call to it adds a new echo
|
|
foo = add-runtime "echo foo";
|
|
# bar will only be included once, no matter how many times it is called
|
|
bar = include-once "bar" (add-runtime "echo bar");
|
|
};
|
|
};
|
|
in
|
|
# Prints:
|
|
# foo
|
|
# foo
|
|
# foo
|
|
# bar
|
|
# Hello, world!
|
|
jail "test" pkgs.hello (c: with c; [
|
|
foo
|
|
foo
|
|
foo
|
|
bar
|
|
bar
|
|
bar
|
|
])
|
|
```
|
|
'';
|
|
impl =
|
|
key: combinator: state:
|
|
if lib.elem key state.includedOnce then
|
|
state
|
|
else
|
|
combinator (helpers.pushState "includedOnce" key state);
|
|
}
|