From 595bc0e2e40375917f907229f32e6b2e1d44e572 Mon Sep 17 00:00:00 2001 From: Alex David Date: Thu, 7 Aug 2025 16:32:58 -0700 Subject: [PATCH] Allow overriding bubblewrap --- lib/jail.nix | 3 ++- tests/test-cases.nix | 17 +++++++++++++++++ website/static-docs/advanced-configuration.md | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/jail.nix b/lib/jail.nix index d4ebee8..e407e2a 100644 --- a/lib/jail.nix +++ b/lib/jail.nix @@ -1,6 +1,7 @@ { pkgs , additionalCombinators ? _: {} , basePermissions ? import ./base-permissions.nix pkgs +, bubblewrapPackage ? pkgs.bubblewrap }: let inherit (pkgs) lib; @@ -21,7 +22,7 @@ in { __functor = _: name: exe: permissions: let initialState = { name = name; - cmd = "${lib.getExe pkgs.bubblewrap}"; + cmd = lib.getExe bubblewrapPackage; entry = if builtins.typeOf exe == "string" then lib.escapeShellArg exe else lib.getExe exe; path = []; argv = "\"$@\""; diff --git a/tests/test-cases.nix b/tests/test-cases.nix index 8452ea2..db227b9 100644 --- a/tests/test-cases.nix +++ b/tests/test-cases.nix @@ -21,6 +21,23 @@ in { (assertStdout (jail' "hello" (sh "cat /build/secret") []) "hunter2") ]; + "it allows overriding the bubblewrap package" = let + jail' = jail-nix.lib.extend { + inherit pkgs; + bubblewrapPackage = pkgs.writeShellApplication { + name = "my-bubblewrap"; + text = '' + # A version of bwrap that just prints its arguments instead of + # actually running a jail. + echo "$@" + ''; + }; + basePermissions = null; + }; + in assertStdout + (jail' "test" "some-entrypoint" []) + "--unshare-user --unshare-ipc --unshare-pid --unshare-net --unshare-uts --unshare-cgroup --new-session -- some-entrypoint"; + "it sets a sane default path" = assertStdout (jail "test" (sh ''echo "$PATH"'') []) defaultPath; diff --git a/website/static-docs/advanced-configuration.md b/website/static-docs/advanced-configuration.md index ce0d444..9417b89 100644 --- a/website/static-docs/advanced-configuration.md +++ b/website/static-docs/advanced-configuration.md @@ -62,3 +62,8 @@ jail = jail-nix.lib.extend { ]; }; ``` + +## bubblewrapPackage + +This configuration option allows you to override what bubblewrap package +jail.nix uses for its jails. The default value is `pkgs.bubblewrap`.