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
41
lib/combinators/readonly-paths-from-var.nix
Normal file
41
lib/combinators/readonly-paths-from-var.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{ combinators, lib, ... }:
|
||||
let
|
||||
inherit (combinators)
|
||||
add-runtime
|
||||
include-once
|
||||
;
|
||||
in
|
||||
{
|
||||
sig = "String -> String -> Permission";
|
||||
doc = ''
|
||||
This binds multiple paths as read-only specified by a single runtime
|
||||
environment variable.
|
||||
|
||||
The first argument to this combinator is the runtime environment variable
|
||||
that contains a list of paths to be bound. The second argument is a
|
||||
deliminator to split the paths (Typically either `" "` or `":"`).
|
||||
|
||||
This is useful for variables like `XDG_DATA_DIRS`, `GTK_PATH`,
|
||||
`XCURSOR_PATH`, etc.
|
||||
|
||||
Example:
|
||||
```nix
|
||||
compose [
|
||||
(readonly-paths-from-var "XDG_DATA_DIRS" ":")
|
||||
(readonly-paths-from-var "XCURSOR_PATH" " ")
|
||||
]
|
||||
```
|
||||
'';
|
||||
impl =
|
||||
var: separator:
|
||||
assert lib.isValidPosixName var;
|
||||
include-once "readonly-paths-from-var-${var}" (add-runtime ''
|
||||
IFS=${lib.escapeShellArg separator} read -ra DIRS <<< "''${${var}-}"
|
||||
for DIR in "''${DIRS[@]}"; do
|
||||
if [ -e "$DIR" ]; then
|
||||
P="$(realpath "$DIR")"
|
||||
RUNTIME_ARGS+=(--ro-bind "$P" "$P")
|
||||
fi
|
||||
done
|
||||
'');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue