Refactor path handling
* Moves the default coreutils path into base permissions to allow override. * Makes paths defined *later* in the permissions list appear *earlier* which should have the effect of later calls to `add-path` override binaries provided by earlier ones. * Makes the `path` variable on state a list rather than a string.
This commit is contained in:
parent
7f17289a72
commit
06c7210127
4 changed files with 7 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ pkgs: let helpers = import ./helpers.nix pkgs; in combinators: with combinators;
|
||||||
(unsafe-add-raw-args "--tmpfs ~")
|
(unsafe-add-raw-args "--tmpfs ~")
|
||||||
(unsafe-add-raw-args "--clearenv")
|
(unsafe-add-raw-args "--clearenv")
|
||||||
(unsafe-add-raw-args "--die-with-parent")
|
(unsafe-add-raw-args "--die-with-parent")
|
||||||
|
(add-pkg-deps [ pkgs.coreutils ])
|
||||||
(readonly "/nix/store")
|
(readonly "/nix/store")
|
||||||
(readonly "/bin/sh")
|
(readonly "/bin/sh")
|
||||||
(fwd-env "LANG")
|
(fwd-env "LANG")
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ in rec {
|
||||||
Appends the passed string to `$PATH`.
|
Appends the passed string to `$PATH`.
|
||||||
'';
|
'';
|
||||||
__functor = _:
|
__functor = _:
|
||||||
path: state: state // { path = "${state.path}:${path}"; }
|
path: state: state // { path = [ path ] ++ state.path; }
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ in {
|
||||||
name = name;
|
name = name;
|
||||||
cmd = "${lib.getExe pkgs.bubblewrap}";
|
cmd = "${lib.getExe pkgs.bubblewrap}";
|
||||||
entry = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
entry = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe;
|
||||||
path = "${pkgs.coreutils}/bin";
|
path = [];
|
||||||
argv = "\"$@\"";
|
argv = "\"$@\"";
|
||||||
runtime = "";
|
runtime = "";
|
||||||
new-session = true;
|
new-session = true;
|
||||||
|
|
@ -51,7 +51,7 @@ in {
|
||||||
unsafe-add-raw-args
|
unsafe-add-raw-args
|
||||||
] s
|
] s
|
||||||
)
|
)
|
||||||
(s: set-env "PATH" s.path s)
|
(s: if builtins.length s.path > 0 then set-env "PATH" (lib.concatStringsSep ":" s.path) s else s)
|
||||||
(s: if s.new-session then unsafe-add-raw-args "--new-session" s else s)
|
(s: if s.new-session then unsafe-add-raw-args "--new-session" s else s)
|
||||||
(s: lib.foldr (envVar:
|
(s: lib.foldr (envVar:
|
||||||
assert pkgs.lib.isValidPosixName envVar;
|
assert pkgs.lib.isValidPosixName envVar;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ in {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
basePermissions = c: [
|
basePermissions = c: [
|
||||||
(c.readonly "/build/secret")
|
(c.readonly "/build/secret")
|
||||||
|
(c.add-pkg-deps [ pkgs.coreutils ])
|
||||||
(c.readonly "/nix/store")
|
(c.readonly "/nix/store")
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
@ -48,13 +49,13 @@ in {
|
||||||
(jail "test" (sh ''echo "$PATH"'') (c: [
|
(jail "test" (sh ''echo "$PATH"'') (c: [
|
||||||
(c.add-path "/some/new/path")
|
(c.add-path "/some/new/path")
|
||||||
]))
|
]))
|
||||||
"${defaultPath}:/some/new/path";
|
"/some/new/path:${defaultPath}";
|
||||||
|
|
||||||
"combinators/add-pkg-deps" = assertStdout
|
"combinators/add-pkg-deps" = assertStdout
|
||||||
(jail "test" (sh ''echo "$PATH"'') (c: [
|
(jail "test" (sh ''echo "$PATH"'') (c: [
|
||||||
(c.add-pkg-deps [ pkgs.hello ])
|
(c.add-pkg-deps [ pkgs.hello ])
|
||||||
]))
|
]))
|
||||||
"${defaultPath}:${pkgs.hello}/bin";
|
"${pkgs.hello}/bin:${defaultPath}";
|
||||||
|
|
||||||
"combinators/bind-pkg" = assertStdout
|
"combinators/bind-pkg" = assertStdout
|
||||||
(jail "test" (sh "cat /foo") (c: [
|
(jail "test" (sh "cat /foo") (c: [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue