about summary refs log tree commit diff
path: root/nixos/modules/programs/firejail.nix
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-07-14 13:25:28 +0800
committerPeter Hoeg <peter@hoeg.com>2018-07-14 20:21:41 +0800
commit65eb3a590d8d5657e3bf8534ddccc827aefc1862 (patch)
treeb7bed37d317858a21ec0289207ec94e4199ce60b /nixos/modules/programs/firejail.nix
parentdae9cf6106da19f79a39714f183ed253c62b32c5 (diff)
downloadnixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar.gz
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar.bz2
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar.lz
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar.xz
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.tar.zst
nixlib-65eb3a590d8d5657e3bf8534ddccc827aefc1862.zip
firejail: add nixos module
Also add support for wrapping binaries with firejail.
Diffstat (limited to 'nixos/modules/programs/firejail.nix')
-rw-r--r--nixos/modules/programs/firejail.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/nixos/modules/programs/firejail.nix b/nixos/modules/programs/firejail.nix
new file mode 100644
index 000000000000..46ee4bc0f7a0
--- /dev/null
+++ b/nixos/modules/programs/firejail.nix
@@ -0,0 +1,48 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.programs.firejail;
+
+  wrappedBins = pkgs.stdenv.mkDerivation rec {
+    name = "firejail-wrapped-binaries";
+    nativeBuildInputs = with pkgs; [ makeWrapper ];
+    buildCommand = ''
+      mkdir -p $out/bin
+      ${lib.concatStringsSep "\n" (lib.mapAttrsToList (command: binary: ''
+      cat <<_EOF >$out/bin/${command}
+      #!${pkgs.stdenv.shell} -e
+      /run/wrappers/bin/firejail ${binary} "\$@"
+      _EOF
+      chmod 0755 $out/bin/${command}
+      '') cfg.wrappedBinaries)}
+    '';
+  };
+
+in {
+  options.programs.firejail = {
+    enable = mkEnableOption "firejail";
+
+    wrappedBinaries = mkOption {
+      type = types.attrs;
+      default = {};
+      description = ''
+        Wrap the binaries in firejail and place them in the global path.
+        </para>
+        <para>
+        You will get file collisions if you put the actual application binary in
+        the global environment and applications started via .desktop files are
+        not wrapped if they specify the absolute path to the binary.
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    security.wrappers.firejail.source = "${lib.getBin pkgs.firejail}/bin/firejail";
+
+    environment.systemPackages = [ wrappedBins ];
+  };
+
+  meta.maintainers = with maintainers; [ peterhoeg ];
+}