Move helpers into lib.nix
This commit is contained in:
parent
dd40b566ac
commit
08e7907337
2 changed files with 16 additions and 8 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
pkgs: let
|
{ pkgs, lib, helpers }: let
|
||||||
escape = rawOrStr: if builtins.typeOf rawOrStr == "string" then pkgs.lib.strings.escapeShellArg rawOrStr else rawOrStr.raw;
|
inherit (helpers) escape noescape;
|
||||||
in rec {
|
in rec {
|
||||||
noescape = value: { raw = value; };
|
# noescape isn't a combinator, but it's a useful helper to expose when defining jails
|
||||||
|
inherit noescape;
|
||||||
|
|
||||||
compose = helpers: state: pkgs.lib.pipe state helpers;
|
compose = helpers: state: lib.pipe state helpers;
|
||||||
|
|
||||||
unsafe-add-raw-args = args: state: state // { cmd = "${state.cmd} ${args}"; };
|
unsafe-add-raw-args = args: state: state // { cmd = "${state.cmd} ${args}"; };
|
||||||
add-path = path: state: state // { path = "${state.path}:${path}"; };
|
add-path = path: state: state // { path = "${state.path}:${path}"; };
|
||||||
|
|
@ -75,10 +76,10 @@ in rec {
|
||||||
write-text = path: contents:
|
write-text = path: contents:
|
||||||
bind-pkg
|
bind-pkg
|
||||||
path
|
path
|
||||||
(pkgs.writeText "jail-write-text-${pkgs.lib.strings.sanitizeDerivationName (escape path)}" contents);
|
(pkgs.writeText "jail-write-text-${lib.strings.sanitizeDerivationName (escape path)}" contents);
|
||||||
|
|
||||||
persisthome = name: compose [
|
persisthome = name: compose [
|
||||||
(add-runtime "mkdir -p ~/.local/share/jails/${pkgs.lib.escapeShellArg name}")
|
(add-runtime "mkdir -p ~/.local/share/jails/${lib.escapeShellArg name}")
|
||||||
(rw-bind (noescape "~/.local/share/jails/${pkgs.lib.escapeShellArg name}") (noescape "~"))
|
(rw-bind (noescape "~/.local/share/jails/${lib.escapeShellArg name}") (noescape "~"))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
lib.nix
9
lib.nix
|
|
@ -3,7 +3,14 @@
|
||||||
|
|
||||||
exe-str = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
exe-str = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
||||||
|
|
||||||
combinators = import ./combinators.nix pkgs;
|
helpers = {
|
||||||
|
escape = rawOrStr: if builtins.typeOf rawOrStr == "string" then lib.strings.escapeShellArg rawOrStr else rawOrStr.raw;
|
||||||
|
noescape = value: { raw = value; };
|
||||||
|
};
|
||||||
|
|
||||||
|
combinators = import ./combinators.nix {
|
||||||
|
inherit pkgs lib helpers;
|
||||||
|
};
|
||||||
|
|
||||||
initial-state = lib.pipe {
|
initial-state = lib.pipe {
|
||||||
cmd = "${lib.getExe pkgs.bubblewrap}";
|
cmd = "${lib.getExe pkgs.bubblewrap}";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue