Expose sh in $PATH in the base combinator

Some software reasonably expects `sh` to exist in PATH. I think I
haven't run into this before since a lot of nixified software explicitly
declares its dependencies on bash, but I've run into a few where this
isn't the case.
This commit is contained in:
Alex David 2025-10-26 09:48:38 -07:00
commit b843338efa
2 changed files with 16 additions and 4 deletions

View file

@ -1,6 +1,12 @@
{ combinators, pkgs, ... }: {
combinators,
pkgs,
helpers,
...
}:
let let
inherit (combinators) inherit (combinators)
add-path
add-pkg-deps add-pkg-deps
ro-bind ro-bind
compose compose
@ -24,7 +30,7 @@ in
* Ensures all processes in the jail are killed when the jail exits * Ensures all processes in the jail are killed when the jail exits
(Using `--die-with-parent` bwrap arg) (Using `--die-with-parent` bwrap arg)
* Adds coreutils to the package deps (`add-pkg-deps [ pkgs.coreutils ]`) * Adds coreutils to the package deps (`add-pkg-deps [ pkgs.coreutils ]`)
* Binds `/bin/sh` from `pkgs.bash` * Binds `/bin/sh` from `pkgs.bash` and adds `/bin` to `$PATH`
(`ro-bind "''${pkgs.bash}/bin/sh" "/bin/sh"`) (`ro-bind "''${pkgs.bash}/bin/sh" "/bin/sh"`)
* Clears the environment except `LANG`, `HOME` and `TERM` * Clears the environment except `LANG`, `HOME` and `TERM`
@ -40,8 +46,10 @@ in
(unsafe-add-raw-args "--tmpfs /tmp") (unsafe-add-raw-args "--tmpfs /tmp")
(unsafe-add-raw-args "--tmpfs ~") (unsafe-add-raw-args "--tmpfs ~")
(unsafe-add-raw-args "--die-with-parent") (unsafe-add-raw-args "--die-with-parent")
(add-pkg-deps [ pkgs.coreutils ])
(ro-bind "${pkgs.bash}/bin/sh" "/bin/sh") (ro-bind "${pkgs.bash}/bin/sh" "/bin/sh")
(add-path "/bin")
(helpers.pushState "additionalRuntimeClosures" pkgs.bash)
(add-pkg-deps [ pkgs.coreutils ])
(unsafe-add-raw-args "--clearenv") (unsafe-add-raw-args "--clearenv")
(fwd-env "LANG") (fwd-env "LANG")
(fwd-env "HOME") (fwd-env "HOME")

View file

@ -20,7 +20,7 @@ spec = parallel $ inTestM $ do
`shouldOutput` "Hello, world!\n" `shouldOutput` "Hello, world!\n"
it "sets a sane default path" $ do it "sets a sane default path" $ do
defaultPath <- evalNixExpr [i| "${pkgs.coreutils}/bin" |] defaultPath <- evalNixExpr [i| "${pkgs.coreutils}/bin:/bin" |]
[i| jail "test" (sh ''echo -n "$PATH"'') [] |] [i| jail "test" (sh ''echo -n "$PATH"'') [] |]
`shouldOutput` defaultPath `shouldOutput` defaultPath
@ -29,6 +29,10 @@ spec = parallel $ inTestM $ do
[i| jail "test" (sh ''echo -n "''${MY_ENV_VAR-unset}"'') [] |] [i| jail "test" (sh ''echo -n "''${MY_ENV_VAR-unset}"'') [] |]
`shouldOutput` "unset" `shouldOutput` "unset"
it "provides `sh` in the default path" $ do
[i| jail "test" (sh ''sh -c "echo hello"'') [] |]
`shouldOutput` "hello\n"
describe "forwarding package overrides to the jailed derivation" $ do describe "forwarding package overrides to the jailed derivation" $ do
-- This is a nix expression of a package that prints out the value of an -- This is a nix expression of a package that prints out the value of an
-- overridable `run`: -- overridable `run`: