Allow overriding jail base permissions

This commit is contained in:
Alex David 2025-08-07 15:29:16 -07:00
commit f18f1cf701
8 changed files with 154 additions and 74 deletions

View file

@ -5,7 +5,7 @@
outputs = { nixpkgs, ... }: let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
jail = import ../lib.nix { inherit pkgs; };
jail-nix.lib.extend = import ../lib.nix;
ansi = clrCode: "[${toString clrCode}m";
green = ansi 32;
@ -36,7 +36,7 @@
if lib.isDerivation testBody then lib.getExe testBody else
throw "Unknown test body type ${type}";
testCases = import ./test-cases.nix { inherit pkgs lib test jail; };
testCases = import ./test-cases.nix { inherit pkgs lib test jail-nix; };
in {
apps.x86_64-linux.runChecks = {
type = "app";

View file

@ -1,11 +1,25 @@
{ pkgs, lib, test, jail }: with test; let
{ pkgs, lib, test, jail-nix }: with test; let
sh = script: (pkgs.writeShellApplication { name = "test-script"; text = script; });
defaultPath = "${pkgs.coreutils}/bin";
jail = jail-nix.lib.extend { inherit pkgs; };
in {
"simple jail works" = assertStdout
(jail "hello" pkgs.hello [])
"Hello, world!";
"it allows overriding base permissions shared across all jails" = let
jail' = jail-nix.lib.extend {
inherit pkgs;
basePermissions = c: [
(c.readonly "/build/secret")
(c.readonly "/nix/store")
];
};
in [
"echo hunter2 > /build/secret"
(assertStdout (jail' "hello" (sh "cat /build/secret") []) "hunter2")
];
"it sets a sane default path" = assertStdout
(jail "test" (sh ''echo "$PATH"'') [])
defaultPath;