From b843338efab3184e2cab7336bac3a0a410177a5e Mon Sep 17 00:00:00 2001 From: Alex David Date: Sun, 26 Oct 2025 09:48:38 -0700 Subject: [PATCH] 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. --- lib/combinators/base.nix | 14 +++++++++++--- tests/spec/JailSpec.hs | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/combinators/base.nix b/lib/combinators/base.nix index 83e552e..8dd52bc 100644 --- a/lib/combinators/base.nix +++ b/lib/combinators/base.nix @@ -1,6 +1,12 @@ -{ combinators, pkgs, ... }: +{ + combinators, + pkgs, + helpers, + ... +}: let inherit (combinators) + add-path add-pkg-deps ro-bind compose @@ -24,7 +30,7 @@ in * Ensures all processes in the jail are killed when the jail exits (Using `--die-with-parent` bwrap arg) * 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"`) * Clears the environment except `LANG`, `HOME` and `TERM` @@ -40,8 +46,10 @@ in (unsafe-add-raw-args "--tmpfs /tmp") (unsafe-add-raw-args "--tmpfs ~") (unsafe-add-raw-args "--die-with-parent") - (add-pkg-deps [ pkgs.coreutils ]) (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") (fwd-env "LANG") (fwd-env "HOME") diff --git a/tests/spec/JailSpec.hs b/tests/spec/JailSpec.hs index 1427e1c..6c23357 100644 --- a/tests/spec/JailSpec.hs +++ b/tests/spec/JailSpec.hs @@ -20,7 +20,7 @@ spec = parallel $ inTestM $ do `shouldOutput` "Hello, world!\n" 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"'') [] |] `shouldOutput` defaultPath @@ -29,6 +29,10 @@ spec = parallel $ inTestM $ do [i| jail "test" (sh ''echo -n "''${MY_ENV_VAR-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 -- This is a nix expression of a package that prints out the value of an -- overridable `run`: