1 { config, lib, pkgs, ... }:
4 inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf maintainers;
6 cfg = config.security.isolate;
7 configFile = pkgs.writeText "isolate-config.cf" ''
8 box_root=${cfg.boxRoot}
9 lock_root=${cfg.lockRoot}
11 first_uid=${toString cfg.firstUid}
12 first_gid=${toString cfg.firstGid}
13 num_boxes=${toString cfg.numBoxes}
14 restricted_init=${if cfg.restrictedInit then "1" else "0"}
17 isolate = pkgs.symlinkJoin {
18 name = "isolate-wrapped-${pkgs.isolate.version}";
20 paths = [ pkgs.isolate ];
22 nativeBuildInputs = [ pkgs.makeWrapper ];
25 wrapProgram $out/bin/isolate \
26 --set ISOLATE_CONFIG_FILE ${configFile}
28 wrapProgram $out/bin/isolate-cg-keeper \
29 --set ISOLATE_CONFIG_FILE ${configFile}
34 options.security.isolate = {
35 enable = mkEnableOption ''
36 Sandbox for securely executing untrusted programs
39 package = mkPackageOption pkgs "isolate-unwrapped" { };
43 default = "/var/lib/isolate/boxes";
45 All sandboxes are created under this directory.
46 To avoid symlink attacks, this directory and all its ancestors
47 must be writeable only by root.
53 default = "/run/isolate/locks";
55 Directory where lock files are created.
61 default = "auto:/run/isolate/cgroup";
63 Control group which subgroups are placed under.
64 Either an explicit path to a subdirectory in cgroupfs, or "auto:file" to read
65 the path from "file", where it is put by `isolate-cg-helper`.
70 type = types.numbers.between 1000 65533;
73 Start of block of UIDs reserved for sandboxes.
78 type = types.numbers.between 1000 65533;
81 Start of block of GIDs reserved for sandboxes.
86 type = types.numbers.between 1000 65533;
89 Number of UIDs and GIDs to reserve, starting from
90 {option}`firstUid` and {option}`firstGid`.
94 restrictedInit = mkOption {
98 If true, only root can create sandboxes.
102 extraConfig = mkOption {
106 Extra configuration to append to the configuration file.
111 config = mkIf cfg.enable {
112 environment.systemPackages = [
116 systemd.services.isolate = {
117 description = "Isolate control group hierarchy daemon";
118 wantedBy = [ "multi-user.target" ];
121 ExecStart = "${isolate}/bin/isolate-cg-keeper";
122 Slice = "isolate.slice";
127 systemd.slices.isolate = {
128 description = "Isolate sandbox slice";
131 meta.maintainers = with maintainers; [ virchau13 ];