2025-04-27 12:29:05 -07:00
|
|
|
# jail.nix
|
|
|
|
|
|
|
|
|
|
A helper to make it easy and ergonomic to wrap your derivations in
|
|
|
|
|
[bubblewrap](https://github.com/containers/bubblewrap).
|
|
|
|
|
|
|
|
|
|
## 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-05-11 14:24:11 -07:00
|
|
|
packages.x86_64-linux.jailed = jail "my-jail" untrusted-package (combinators: with combinators; [
|
2025-04-27 12:29:05 -07:00
|
|
|
# By default, only the bare minimum permissions are exposed, in this list
|
|
|
|
|
# you can add additional permissions that you want the program to have.
|
2025-05-11 14:24:11 -07:00
|
|
|
# See ./combinators.nix 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")
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
```
|