1 { config, lib, pkgs, ... }:
4 cfg = config.programs.firejail;
6 wrappedBins = pkgs.runCommand "firejail-wrapped-binaries"
7 { preferLocalBuild = true;
8 allowSubstitutes = false;
9 # take precedence over non-firejailed versions
14 mkdir -p $out/share/applications
15 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (command: value:
17 opts = if builtins.isAttrs value
19 else { executable = value; desktop = null; profile = null; extraArgs = []; };
20 args = lib.escapeShellArgs (
22 ++ (lib.optional (opts.profile != null) "--profile=${builtins.toString opts.profile}")
26 cat <<_EOF >$out/bin/${command}
27 #! ${pkgs.runtimeShell} -e
28 exec /run/wrappers/bin/firejail ${args} -- ${builtins.toString opts.executable} "\$@"
30 chmod 0755 $out/bin/${command}
32 ${lib.optionalString (opts.desktop != null) ''
33 substitute ${opts.desktop} $out/share/applications/$(basename ${opts.desktop}) \
34 --replace ${opts.executable} $out/bin/${command}
36 '') cfg.wrappedBinaries)}
40 options.programs.firejail = {
41 enable = lib.mkEnableOption "firejail, a sandboxing tool for Linux";
43 wrappedBinaries = lib.mkOption {
44 type = lib.types.attrsOf (lib.types.either lib.types.path (lib.types.submodule {
46 executable = lib.mkOption {
47 type = lib.types.path;
48 description = "Executable to run sandboxed";
49 example = lib.literalExpression ''"''${lib.getBin pkgs.firefox}/bin/firefox"'';
51 desktop = lib.mkOption {
52 type = lib.types.nullOr lib.types.path;
54 description = ".desktop file to modify. Only necessary if it uses the absolute path to the executable.";
55 example = lib.literalExpression ''"''${pkgs.firefox}/share/applications/firefox.desktop"'';
57 profile = lib.mkOption {
58 type = lib.types.nullOr lib.types.path;
60 description = "Profile to use";
61 example = lib.literalExpression ''"''${pkgs.firejail}/etc/firejail/firefox.profile"'';
63 extraArgs = lib.mkOption {
64 type = lib.types.listOf lib.types.str;
66 description = "Extra arguments to pass to firejail";
67 example = [ "--private=~/.firejail_home" ];
72 example = lib.literalExpression ''
75 executable = "''${lib.getBin pkgs.firefox}/bin/firefox";
76 profile = "''${pkgs.firejail}/etc/firejail/firefox.profile";
79 executable = "''${lib.getBin pkgs.mpv}/bin/mpv";
80 profile = "''${pkgs.firejail}/etc/firejail/mpv.profile";
85 Wrap the binaries in firejail and place them in the global path.
90 config = lib.mkIf cfg.enable {
91 security.wrappers.firejail =
95 source = "${lib.getBin pkgs.firejail}/bin/firejail";
98 environment.systemPackages = [ pkgs.firejail ] ++ [ wrappedBins ];
101 meta.maintainers = with lib.maintainers; [ peterhoeg ];