KDE Ni! OS – Firejail and browser sandboxes

Wait 5 sec.

KDE Ni! OS is a custom flavour(configuration, not a separate distribution) of NixOS that showcases KDE software. Itbuilds on NixOS with the aim to reimplement the same features otherpopular immutable distributions have, while providing a first-class KDEPlasma setup.I got the idea for Ni! OS during the previous Akademy (2025), when Ilistened to presentations on KDE Linux and Kubuntu Core. During thisyear’s Akademy I got reminded I forgot to write about Ni! for quite awhile.One of the new features I’ve been testing is meant to improve privacyand security of Ni! OS users – the ability to easily define web browsersandboxes.I’ve been a heavy user of Firefox profiles for a long time now. So,this is not about creating a single web browser sandbox, but a customset of sandboxes that are completely isolated from each other and fromthe rest of the system.In order to define a list of sandboxes in Ni! OS, one only needs tochange definitions.nix and add all the desiredsandbox/profiles.firejailedBrowsers = [ { browser = "librewolf"; name = "banking"; } { browser = "firefox"; name = "social"; } { browser = "librewolf"; name = "kde"; privateDirectory = "/kde/.librewolf"; }This will create commands librewolf-banking,firefox-social and librewolf-kde that invokefirejail --private=PRIVATE_DIR librewolf (orfirefox). If you don’t specifyprivateDirectory, it will be set to.local/share/firejail-sandbox-browsers/PROFILE_COMMAND_NAME.When the browser is started in the sandbox, it has no access to theoutside system. Not even the portals thing. If you want toaccess any of your files from inside the sandbox, you will need to copyit yourself to the private directory of that sandbox.ImplementationThe implementation of the Ni! module that takes these definitions andcreates sandboxed commands(ni/modules/firejail-browsers.nix) is as follows:{ config, pkgs, lib, ... }:let availableBrowserPackages = { firefox = { package = pkgs.firefox; executable = "firefox"; firejailProfileName = "firefox"; }; librewolf = { package = pkgs.librewolf; executable = "librewolf"; firejailProfileName = "librewolf"; }; chromium = { package = pkgs.chromium; executable = "chromium"; firejailProfileName = "chromium"; }; ungoogled-chromium = { package = pkgs.ungoogled-chromium; executable = "chromium"; firejailProfileName = "chromium"; }; }; makeBrowserInstance = { browser, name, command ? "${browser}-${name}", privateDirectory ? "/home/${config.definitions.user}/.local/share/firejail-sandbox-browsers/${browser}-${name}", }: let config = availableBrowserPackages.${browser}; in { inherit command; value = { executable = "${config.package}/bin/${config.executable}"; profile = "${pkgs.firejail}/etc/firejail/${config.firejailProfileName}.profile"; extraArgs = [ "--private=${privateDirectory}" ]; }; };in { programs.firejail = { enable = true; wrappedBinaries = builtins.listToAttrs ( map (instance: let result = makeBrowserInstance instance; in { name = result.command; value = result.value; }) config.definitions.firejailedBrowsers ); };}It is not yet added to the repository as I want to do a few moretweaks, but copy-pasting the above code into your Ni! OS or NixOS setupshould work.P.S. I know firejail is SUID-based, and SUID is evil.But it works. And works really well.Merlin isolated – Excalibur (1981)