Add wrap-entry combinator
This commit is contained in:
parent
83738cbb8e
commit
8d9acc76f3
2 changed files with 37 additions and 4 deletions
|
|
@ -133,7 +133,11 @@
|
|||
This can write to `$RUNTIME_ARGS` to push additional bubblewrap flags
|
||||
dependant on runtime conditions.
|
||||
|
||||
For example:
|
||||
Note that anything added here is *not* run inside the jail. To run
|
||||
arbitrary things at runtime inside the jail see
|
||||
[wrap-entry](#wrap-entry).
|
||||
|
||||
Example:
|
||||
```nix
|
||||
add-runtime ${"''"}
|
||||
# binds /foo only if /bar exists on the host
|
||||
|
|
@ -148,6 +152,35 @@
|
|||
;
|
||||
};
|
||||
|
||||
wrap-entry = {
|
||||
sig = "(String -> String) -> Combinator";
|
||||
doc = ''
|
||||
Wraps the binary to be jailed in a bash script that will be the new
|
||||
entrypoint to the jail.
|
||||
|
||||
This similar in spirit to the [add-runtime combinator](#add-runtime),
|
||||
except that this runs *inside* the jail, while `add-runtime` runs before
|
||||
the jail starts.
|
||||
|
||||
Example:
|
||||
```nix
|
||||
wrap-entry (entry: ${"''"}
|
||||
echo 'Inside the jail!'
|
||||
''${entry}
|
||||
echo 'Cleaning up...'
|
||||
${"''"})
|
||||
```
|
||||
'';
|
||||
impl = _:
|
||||
getWrapper: state: state // {
|
||||
entry = lib.getExe (pkgs.writeShellApplication {
|
||||
name = "${state.name}-jail-wrapper";
|
||||
text = getWrapper state.entry;
|
||||
});
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
add-pkg-deps = {
|
||||
sig = "[Package] -> Combinator";
|
||||
doc = ''
|
||||
|
|
|
|||
6
lib.nix
6
lib.nix
|
|
@ -1,8 +1,6 @@
|
|||
{ pkgs, name, exe, getOpts }: let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
exe-str = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
||||
|
||||
helpers = rec {
|
||||
dataDir = "~/.local/share/jail.nix";
|
||||
dataDirSubPath = subPath: "${dataDir}/${combinators.escape subPath}";
|
||||
|
|
@ -13,7 +11,9 @@
|
|||
(import ./combinators.nix { inherit pkgs lib helpers; });
|
||||
|
||||
initial-state = {
|
||||
name = name;
|
||||
cmd = "${lib.getExe pkgs.bubblewrap}";
|
||||
entry = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
||||
path = "${pkgs.coreutils}/bin";
|
||||
argv = "\"$@\"";
|
||||
runtime = "";
|
||||
|
|
@ -77,7 +77,7 @@ in lib.pipe initial-state (
|
|||
(state: ''
|
||||
RUNTIME_ARGS=()
|
||||
${state.runtime}
|
||||
exec ${state.cmd} "''${RUNTIME_ARGS[@]}" -- ${exe-str} ${state.argv}
|
||||
exec ${state.cmd} "''${RUNTIME_ARGS[@]}" -- ${state.entry} ${state.argv}
|
||||
'')
|
||||
(text: pkgs.writeShellApplication { inherit name text; })
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue