# firefox-container-controller-extension.nix # Import this file in your configuration.nix to build and install the Container Controller extension. # Usage in configuration.nix: # # let # containerControllerXpi = import ./firefox-container-controller-extension.nix { inherit pkgs; }; # in { # programs.firefox = { # enable = true; # profiles.default = { # extensions = [ containerControllerXpi ]; # }; # }; # } { pkgs }: pkgs.runCommand "firefox-containercontroller-xpi" { nativeBuildInputs = [ pkgs.zip ]; } '' # Create temp dir for packaging TMPDIR=$(mktemp -d) cd "$TMPDIR" # Write manifest.json without leading spaces cat > manifest.json << 'EOF' { "manifest_version": 2, "name": "Container Controller", "version": "1.0", "applications": { "gecko": { "id": "containercontroller@cloonar.com" } }, "permissions": ["containers", "nativeMessaging"], "background": { "scripts": ["background.js"] } } EOF # Write background.js without indentation cat > background.js << 'EOF' async function poll() { const resp = await browser.runtime.sendNativeMessage( "com.firefox.containercontroller", {} ); if (resp.userContextId && resp.action) { try { if (resp.action === "hide") { await browser.containers.hideContainer({ userContextId: resp.userContextId }); } else if (resp.action === "show") { await browser.containers.showContainer({ userContextId: resp.userContextId }); } } catch (e) {} } } // Poll every second setInterval(poll, 1000); EOF # Ensure the Firefox extensions directory exists in the output mkdir -p "$out/share/firefox/extensions" # Create ZIP archive at root of package # and use the updated extension id for the filename zip -r "$out/share/firefox/extensions/containercontroller@cloonar.com.xpi" manifest.json background.js # Clean up rm -rf "$TMPDIR" ''