No description
  • Nix 50.8%
  • Haskell 49.1%
Find a file
Alex David fce1224bdd Use __functor to simplify combinators
By using `__functor` combinators can call each other directly by using
`rec` rather than needing to mapAttrs over all of the combinators to
inject them into each one.
2025-06-13 22:14:13 -07:00
website Use __functor to simplify combinators 2025-06-13 22:14:13 -07:00
combinators.nix Use __functor to simplify combinators 2025-06-13 22:14:13 -07:00
flake.nix Rename getOpts to applyCombinators 2025-06-07 16:37:26 -07:00
lib.nix Use __functor to simplify combinators 2025-06-13 22:14:13 -07:00
LICENSE Add initial spike 2025-04-27 12:07:03 -07:00
README.md Add mailing list link 2025-06-07 16:50:40 -07:00

jail.nix

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

Please send patches, questions and discussions to my general mailing list.

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 (combinators: with 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.