2025-10-19 11:44:21 -07:00
|
|
|
# jail.nix [](https://builds.sr.ht/~alexdavid/jail.nix/commits/main?)
|
2025-04-27 12:29:05 -07:00
|
|
|
|
2025-10-19 11:44:21 -07:00
|
|
|
<!-- Thanks to ~whynothugo for inspiration for this set of links: -->
|
|
|
|
|
[Docs](https://alexdav.id/projects/jail-nix/)
|
|
|
|
|
| [Source](https://git.sr.ht/~alexdavid/jail.nix)
|
|
|
|
|
| [Issues](https://todo.sr.ht/~alexdavid/jail.nix)
|
|
|
|
|
| [Patches](https://lists.sr.ht/~alexdavid/general)
|
|
|
|
|
| [Matrix](https://matrix.to/#/#jail.nix:woh.place)
|
2025-08-15 08:19:53 -07:00
|
|
|
|
2025-04-27 12:29:05 -07:00
|
|
|
A helper to make it easy and ergonomic to wrap your derivations in
|
|
|
|
|
[bubblewrap](https://github.com/containers/bubblewrap).
|
|
|
|
|
|
2025-10-13 18:19:09 -07:00
|
|
|
|
2025-09-04 15:10:25 -07:00
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
|
|
Documentation to install and get started can be found
|
|
|
|
|
[here](https://alexdav.id/projects/jail-nix).
|
|
|
|
|
|
2025-04-27 12:29:05 -07:00
|
|
|
## Example
|
|
|
|
|
|
|
|
|
|
```nix
|
|
|
|
|
# flake.nix
|
|
|
|
|
{
|
|
|
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
|
|
|
|
inputs.jail-nix.url = "sourcehut:~alexdavid/jail.nix";
|
|
|
|
|
|
|
|
|
|
outputs = { nixpkgs, jail-nix, ... }: let
|
|
|
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
|
|
|
jail = jail-nix.lib.init pkgs;
|
|
|
|
|
|
|
|
|
|
untrusted-package = pkgs.writeScriptBin "untrusted" ''
|
|
|
|
|
ls -la $HOME
|
|
|
|
|
'';
|
|
|
|
|
in {
|
2025-07-11 11:44:12 -07:00
|
|
|
packages.x86_64-linux.jailed = jail "my-jail" untrusted-package (with jail.combinators; [
|
2025-06-07 16:37:46 -07:00
|
|
|
# See combinators section below for more functions that can go here
|
2025-04-27 12:29:05 -07:00
|
|
|
|
|
|
|
|
# Give program access to the network
|
|
|
|
|
network
|
|
|
|
|
|
2025-05-28 09:33:25 -07:00
|
|
|
# Allow program to create windows
|
2025-04-27 12:29:05 -07:00
|
|
|
gui
|
|
|
|
|
|
|
|
|
|
# Give program access to the GPU
|
|
|
|
|
gpu
|
|
|
|
|
|
|
|
|
|
# Give program read-only access to /var/log/journal
|
|
|
|
|
(readonly "/var/log/journal")
|
|
|
|
|
|
|
|
|
|
# Mount ~/foo to /bar in the jail as read-write
|
|
|
|
|
# (noescape due to `~` — all arguments are shell escaped by default)
|
|
|
|
|
(rw-bind (noescape "~/foo") "/bar")
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
```
|
2025-06-07 16:37:46 -07:00
|
|
|
|
|
|
|
|
## Combinators
|
|
|
|
|
|
|
|
|
|
By default, only the bare minimum permissions are exposed. By passing
|
|
|
|
|
combinators into the jail you can modify the jail to expose more permissions.
|
|
|
|
|
|
|
|
|
|
[Click here](https://alexdav.id/projects/jail-nix/combinators/) for a full list
|
|
|
|
|
of combinators and their documentation.
|
2025-10-19 11:44:21 -07:00
|
|
|
|
|
|
|
|
## Help / Comments / Suggestions
|
|
|
|
|
|
|
|
|
|
I am working on docs with examples of combinators for various common software
|
|
|
|
|
projects, but this isn't finished yet. In the meantime, if you need help
|
|
|
|
|
jailing software, run into issues, or have suggestions, feel free to join
|
|
|
|
|
[#jail.nix:woh.place](https://matrix.to/#/#jail.nix:woh.place) on matrix, or
|
|
|
|
|
[open an issue](https://todo.sr.ht/~alexdavid/jail.nix).
|