No description
  • Nix 50.8%
  • Haskell 49.1%
Find a file
Alex David 1d8ec0b1cc Lock down GPU combinator
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.
2025-10-19 11:30:21 -07:00
lib Lock down GPU combinator 2025-10-19 11:30:21 -07:00
tests Add tests for the seccomp combinator 2025-10-18 22:44:01 -07:00
website Pull remaining default perms into base combinator 2025-10-10 16:28:45 -07:00
.build.yml Fix time-zone combinator 2025-09-15 22:26:44 -07:00
default.nix Allow consuming jail.nix without flakes 2025-08-15 08:06:02 -07:00
flake.nix Restructure source 2025-08-07 15:54:50 -07:00
LICENSE Add initial spike 2025-04-27 12:07:03 -07:00
README.md Add link to matrix channel to readme 2025-10-13 18:19:09 -07:00

jail.nix

builds.sr.ht status

A helper to make it easy and ergonomic to wrap your derivations in bubblewrap.

Please report bugs and feature requests to the issue tracker. Please send patches, questions and discussions to my mailing list.

If you prefer to chat, feel free to join the matrix channel #jail.nix:woh.place to ask questions, discuss ideas, or report issues. I am also usually around and happy to help debug jailing software if you are having issues.

Getting Started

Documentation to install and get started can be found here.

Example

# 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 {
    packages.x86_64-linux.jailed = jail "my-jail" untrusted-package (with jail.combinators; [
      # See combinators section below for more functions that can go here

      # Give program access to the network
      network

      # Allow program to create windows
      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")
    ]);
  };
}

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 for a full list of combinators and their documentation.