Bind write-text/bind-pkg runtime closure

39ca901 introduced only bind-mounting in the individual store paths that
make up the runtime closure for the jail. However, in practice I found a
few jails that were using `write-text` for configuration files that
referenced other store paths were no longer being bind mounted into the
jail.

I think it's reasonable that if you `write-text` or `bind-pkg`, and it
has runtime dependencies, those dependencies should be made available to
the jail.
This commit is contained in:
Alex David 2025-08-17 17:01:39 -07:00
commit b28610bb1e
3 changed files with 10 additions and 1 deletions

View file

@ -634,6 +634,7 @@ in rec {
include-once "bind-nix-store-runtime-closure" (defer (state: include-once "bind-nix-store-runtime-closure" (defer (state:
let let
runtimeClosure = pkgs.writeText "${state.name}-runtime-closure" '' runtimeClosure = pkgs.writeText "${state.name}-runtime-closure" ''
${pkgs.lib.concatStringsSep "\n" state.additionalRuntimeClosures}
${pkgs.lib.concatStringsSep "\n" state.path} ${pkgs.lib.concatStringsSep "\n" state.path}
${state.argv} ${state.argv}
${state.entry} ${state.entry}
@ -872,7 +873,10 @@ in rec {
``` ```
''; '';
__functor = _: __functor = _:
path: pkg: ro-bind (toString pkg) path path: pkg: compose [
(ro-bind (toString pkg) path)
(state: state // { additionalRuntimeClosures = state.additionalRuntimeClosures ++ [ pkg ]; })
]
; ;
}; };

View file

@ -34,6 +34,7 @@ in {
includedOnce = []; # See include-once combinator includedOnce = []; # See include-once combinator
cleanup = []; # See cleanup combinator cleanup = []; # See cleanup combinator
deferredPermissions = []; # See defer combinator deferredPermissions = []; # See defer combinator
additionalRuntimeClosures = []; # See bind-nix-store-runtime-closure
}; };
in lib.pipe initialState ( in lib.pipe initialState (
# Permissions shared by all invocations of jail # Permissions shared by all invocations of jail

View file

@ -26,6 +26,7 @@ in {
argv = mkDep "argv"; argv = mkDep "argv";
entry = mkDep "entry"; entry = mkDep "entry";
unrelated = sh "echo this dep is unrelated"; unrelated = sh "echo this dep is unrelated";
write-text = mkDep "write-text";
}; };
checkExists = jail checkExists = jail
"check-exists" "check-exists"
@ -40,6 +41,7 @@ in {
(c: [ (c: [
(c.add-pkg-deps [ deps.add-pkg-deps.parent ]) (c.add-pkg-deps [ deps.add-pkg-deps.parent ])
(c.set-argv [ (c.noescape "\"$1\"") deps.argv.parent ]) (c.set-argv [ (c.noescape "\"$1\"") deps.argv.parent ])
(c.write-text "/write/text/with/runtime/dep" "${deps.write-text.parent}")
]); ]);
in in
# Dependencies that should be in the jail # Dependencies that should be in the jail
@ -47,6 +49,7 @@ in {
deps.add-pkg-deps.runtime deps.add-pkg-deps.runtime
deps.argv.runtime deps.argv.runtime
deps.entry.runtime deps.entry.runtime
deps.write-text.runtime
] ]
++ ++
# Dependencies that shouldn't be in the jail # Dependencies that shouldn't be in the jail
@ -55,6 +58,7 @@ in {
deps.argv.buildtime deps.argv.buildtime
deps.entry.buildtime deps.entry.buildtime
deps.unrelated deps.unrelated
deps.write-text.buildtime
]; ];
"it allows overriding base permissions shared across all jails" = let "it allows overriding base permissions shared across all jails" = let