I have a few combinator ideas that I'd like to try adding but I still
haven't fully fleshed them out yet. In order to reduce breaking people's
setup, this introduces a new `experimental` flag on combinators that
separates them on the docs website to let users know that their design
may not be fully finalized yet.
To make it easier to rename combinators without breaking anyone's
configuration, this change allows combinators to specify a list of
`aliases` that are also exported from `jail.combinators`.
The aliases are also documented on the documentation website.
These have been deprecated for some time now, and were deprecated before
I gave my nixcon talk which brought attention to this library. So I
think it's pretty doubtful that anyone is still using these.
Jail.nix does not expose `$PATH` by default because the automatic
runtime-closure binding often means your `$PATH` won't work anyway.
However, for some jails, you may want to disable the runtime-closure
binding and just bind your whole nix store. In those cases, it would be
nice if `fwd-env "PATH"` worked correctly.
At some point example.org changed something about their certificate
chain and causes `curl https://example.org` to fail on NixOS systems.
For now, I'm going to use `https://alexdav.id`.
If an environment variable is unset, `try-fwd-env` will set it to an
empty string. This can cause issues for programs that treat unset and
empty environment variables differently. For instance, when jailing
Spotify with the `pulse` combinator, `$PULSE_SERVER` gets set to an
empty string, Spotify tries to use it as-is, fails, and then falls back
to using ALSA.
Ideally I would've liked to wire this into the existing env logic
somehow but it's a bit tricky to do since `--setenv` needs to be
provided to Bubblewrap conditionally based on a value that isn't known
until the script is executed. Bubblewrap appears to handle `--setenv`
being specified multiple times for the same variable okay, so not using
the existing env logic doesn't break the ability to override environment
variables.
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.
* Allow running test apps in repo root (e.g. `nix run ./tests#runTests`)
* Pass argv to cabal to allow filtering tests with `-m`
* Use `cabal run spec` rather than `cabal test`
This is one of the original combinators I wrote for myself before even
open sourcing jail.nix. It was exposing all of `/sys` which is
unnecessary.
With this change, only `/sys/dev/char` is shared, (which should only
contain symlinks), and any PCI devices that contain a `drm` directory.
This seems to be the most reliable way I can tell of finding GPUs from
testing various combinations of distros and GPUs. The other signal seems
to be if `class` is `0x030000`, although I struggled to find
documentation where these classes are defined, and if they are in-fact
constant across all linux systems.
Anyway, this is a massive improvement over binding all of `/sys`, and
hopefully not a breaking change for anyone. If anyone runs into issues,
or has suggestions on better approaches I would love to hear it.
This combinator allows for the use of bubblewrap's `--add-seccomp-fd`
option. Since multiple invocations of this combinator are allowed, this
commit also introduces a new state attribute `seccompPermissions`.
The implementation uses `test -x` against the given argument to decide
whether to use input redirection to a FD or process substitution.
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
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.
`base-permissions.nix` was the source of truth for all of the base
combinators, but it was not documented well anywhere.
To make this easier and more obvious for users, this commit pulls all
remaining custom permissions into a new `base` combinator which is
included by default. This way there is no more undocumented permissions
included by default, they are all documented in the `Default included
combinators` section of the docs.
This should also make it easier to override base permissions because
users can now just specify `base` instead of all of the
`unsafe-add-raw-args` calls unless they really want to change them.
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.
The `lib/combinators.nix` file was getting quite long and some ideas I
have for future combinators may even require ancillary files. To help
scale these changes, this commit breaks each combinator into its own
file under the `lib/combinators` directory.
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
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.