1 { config, lib, pkgs, ... }:
6 cfg = config.programs.firejail;
8 wrappedBins = pkgs.runCommand "firejail-wrapped-binaries"
9 { preferLocalBuild = true;
10 allowSubstitutes = false;
11 # take precedence over non-firejailed versions
16 mkdir -p $out/share/applications
17 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (command: value:
19 opts = if builtins.isAttrs value
21 else { executable = value; desktop = null; profile = null; extraArgs = []; };
22 args = lib.escapeShellArgs (
24 ++ (optional (opts.profile != null) "--profile=${toString opts.profile}")
28 cat <<_EOF >$out/bin/${command}
29 #! ${pkgs.runtimeShell} -e
30 exec /run/wrappers/bin/firejail ${args} -- ${toString opts.executable} "\$@"
32 chmod 0755 $out/bin/${command}
34 ${lib.optionalString (opts.desktop != null) ''
35 substitute ${opts.desktop} $out/share/applications/$(basename ${opts.desktop}) \
36 --replace ${opts.executable} $out/bin/${command}
38 '') cfg.wrappedBinaries)}
42 options.programs.firejail = {
43 enable = mkEnableOption (lib.mdDoc "firejail");
45 wrappedBinaries = mkOption {
46 type = types.attrsOf (types.either types.path (types.submodule {
48 executable = mkOption {
50 description = lib.mdDoc "Executable to run sandboxed";
51 example = literalExpression ''"''${lib.getBin pkgs.firefox}/bin/firefox"'';
54 type = types.nullOr types.path;
56 description = lib.mkDoc ".desktop file to modify. Only necessary if it uses the absolute path to the executable.";
57 example = literalExpression ''"''${pkgs.firefox}/share/applications/firefox.desktop"'';
60 type = types.nullOr types.path;
62 description = lib.mdDoc "Profile to use";
63 example = literalExpression ''"''${pkgs.firejail}/etc/firejail/firefox.profile"'';
65 extraArgs = mkOption {
66 type = types.listOf types.str;
68 description = lib.mdDoc "Extra arguments to pass to firejail";
69 example = [ "--private=~/.firejail_home" ];
74 example = literalExpression ''
77 executable = "''${lib.getBin pkgs.firefox}/bin/firefox";
78 profile = "''${pkgs.firejail}/etc/firejail/firefox.profile";
81 executable = "''${lib.getBin pkgs.mpv}/bin/mpv";
82 profile = "''${pkgs.firejail}/etc/firejail/mpv.profile";
86 description = lib.mdDoc ''
87 Wrap the binaries in firejail and place them in the global path.
92 config = mkIf cfg.enable {
93 security.wrappers.firejail =
97 source = "${lib.getBin pkgs.firejail}/bin/firejail";
100 environment.systemPackages = [ pkgs.firejail ] ++ [ wrappedBins ];
103 meta.maintainers = with maintainers; [ peterhoeg ];