Split combinators into files
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.
This commit is contained in:
parent
8fa6d132e1
commit
6181276ae1
54 changed files with 1531 additions and 1260 deletions
32
lib/combinators/add-cleanup.nix
Normal file
32
lib/combinators/add-cleanup.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{ helpers, ... }:
|
||||
{
|
||||
sig = "String -> Permission";
|
||||
doc = ''
|
||||
Adds arbitrary logic to run when the jail exits.
|
||||
|
||||
This is designed to be an easy way to register cleanup actions for things
|
||||
created in [add-runtime](#add-runtime). These scripts run in the same
|
||||
scope as `add-runtime` so any shell variables defined there will be in
|
||||
scope.
|
||||
|
||||
The cleanup actions may run even if the runtime doesn't— for example if a
|
||||
previous runtime exits non-zero the jail will exit prematurely, but the
|
||||
cleanup actions will still run.
|
||||
|
||||
Example:
|
||||
```nix
|
||||
compose [
|
||||
(add-runtime ${"''"}
|
||||
TMP_FILE=$(mktemp)
|
||||
do-something "$TMP_FILE"
|
||||
${"''"})
|
||||
(add-cleanup ${"''"}
|
||||
if [ -e "${"''"}''${TMP_FILE-}" ]; then
|
||||
rm "$TMP_FILE"
|
||||
fi
|
||||
${"''"})
|
||||
]
|
||||
```
|
||||
'';
|
||||
impl = helpers.pushState "cleanup";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue