Commit graph

31 commits

Author SHA1 Message Date
Mathias Sven
9857627b48 Add tests for the seccomp combinator 2025-10-18 22:44:01 -07:00
Alex David
d596e0bc81 Fix time-zone combinator on missing /etc/localtime
Thanks ~charlie-collard for reporting this

Fixes https://todo.sr.ht/~alexdavid/jail.nix/2
2025-10-14 19:38:49 -07:00
Alex David
f55483fb38 Forward override to jailed derivations
On Nixos, it may be desirable to install some software using
`programs.*.enable = true`. Jail.nix mostly supports this because you
can either use `jail-nix.mkOverlay`, or just use Nixos
`programs.*.package = jail ...` to inject a jailed version of the
package.

However, for some modules, like Firefox, the Nixos module calls
`override` on the package. Normally, you would just call `override` on
the package passed into jail, but this is not possible to do within a
Nixos module.

To address this, this patch will check to see if a package passed into
jail has an `override` field, and if so will add an `override` on the
jailed derivation that passes the override function to the entrypoint.

Thanks to ~juanjakobo for reporting this!

Fixes https://todo.sr.ht/~alexdavid/jail.nix/1
2025-10-13 16:06:29 -07:00
Alex David
dffe5d150c Update readonly-paths-from-var test case
In 8fa6d132e1, ~mathiassven submitted a
patch that fixes the `readonly-paths-from-var` combinator omitting the
final path.

The tests didn't catch this since the final path in the test was a
non-existent path.

This commit backfills the test to catch regressions related to this bug.
The test now makes sure that the first, last, and at least one middle
test path are real paths that show up in the jail.
2025-10-10 16:45:13 -07:00
Alex David
e45e8a7ccb Only forward valid URLs in open-urls-in-browser
This is unlikely to be exploited since the combinator only allows a
single argument and is not parsed by any shell, but it seems like a good
thing to ensure that only valid non-local URLs will be forwarded to
$BROWSER.
2025-10-10 16:28:45 -07:00
Alex David
977c3f2426 Add notifications combinator 2025-10-10 16:28:45 -07:00
Alex David
61b0a147af Use coreutils from nixpkgs rather than from PATH
Before this change, combinators that call `add-runtime` were assuming
coreutils were available, however `add-runtime` did not inject coreutils
as a runtime input.

This also removes forwarding $PATH in the tests which should catch any
issues like this in the future.

Thanks Epsylon for the report:
https://lists.sr.ht/~alexdavid/general/%3C331f3203-d6bf-4c53-824c-4d05088ec47e@gmail.com%3E
2025-10-03 10:53:39 -07:00
Alex David
3610987241 Allow multiple calls to dbus combinator
Before this change, additional calls to the dbus combinator would add
multiple `xdg-dbus-proxy` instances, but only the latest call would be
forwarded into the jail.

With this change, all permissions are saved in state, then, in a
deferred `add-runtime` we add a single `xdg-dbus-proxy` exposing the
union of all previous dbus calls.

This should allow writing combinators that expose dbus permissions like
notifications, or reading light/dark mode changes which can be composed
just like the other non-dbus combinators.
2025-09-28 15:44:36 -07:00
Alex David
7f20103af7 Explicitly declare ghc version for tests 2025-09-27 21:48:39 -07:00
Alex David
3ccf1d42e2 Add try-* bind combinators 2025-09-27 10:51:19 -07:00
Alex David
45c2b47d71 Fix time-zone combinator
Most software that wants to know the timezone reads the symlink in
`/etc/localtime`. A previous update broke this assumption when
attempting to fix the combinator to work on non-NixOS systems.

This change should fix the time-zone combinator in both NixOS and
non-NixOS systems.
2025-09-15 22:26:44 -07:00
Alex David
700189112f Format nix files with nixfmt-tree 2025-09-11 07:31:48 -07:00
Alex David
6fbd3729cc Add mkOverlay 2025-09-02 15:39:40 -07:00
Alex David
8b6484c870 Generate random DBus bus names for tests 2025-09-01 21:57:41 -07:00
Alex David
d35e9df391 Add open-urls-in-browser combinator 2025-09-01 21:47:48 -07:00
Alex David
f5cc61ef63 Add jail-to-host-channel combinator 2025-09-01 21:47:48 -07:00
Alex David
7dc202a5a7 Add dbus combinator 2025-09-01 21:47:48 -07:00
Alex David
275a1296e7 Fix network combinator binding too many paths 2025-09-01 21:47:48 -07:00
Alex David
d8b14ca5ee Rewrite tests in haskell 2025-08-27 12:14:55 -07:00
Alex David
b28610bb1e 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.
2025-08-27 12:14:55 -07:00
Alex David
7d3efead61 Only expose runtime closure by default
Instead of binding the entire `/nix/store`. This behavior can be changed
by overriding `basePermissions`.
2025-08-27 12:14:55 -07:00
Alex David
1f7587326e Don't parallelize tests
On CI this causes them to be flaky since sometimes they output
`error (ignored): error: SQLite database ... is busy`.
2025-08-15 08:12:21 -07:00
Alex David
c37ae887fd Allow consuming jail.nix without flakes 2025-08-15 08:06:02 -07:00
Alex David
595bc0e2e4 Allow overriding bubblewrap 2025-08-07 16:32:58 -07:00
Alex David
06c7210127 Refactor path handling
* Moves the default coreutils path into base permissions to allow
  override.
* Makes paths defined *later* in the permissions list appear *earlier*
  which should have the effect of later calls to `add-path` override
  binaries provided by earlier ones.
* Makes the `path` variable on state a list rather than a string.
2025-08-07 16:26:18 -07:00
Alex David
c7685334cf Restructure source 2025-08-07 15:54:50 -07:00
Alex David
f18f1cf701 Allow overriding jail base permissions 2025-08-07 15:29:16 -07:00
Alex David
ac316857f4 Allow unset readonly-paths-from-var variable 2025-07-21 20:19:50 -07:00
Alex David
ba42171b16 Add readonly-paths-from-var combinator 2025-07-18 11:30:55 -07:00
Alex David
3abb0273cd Add app to run all tests with nice output 2025-07-18 10:46:48 -07:00
Alex David
38b5138956 Add initial simple test cases 2025-07-17 20:25:17 -07:00