# modules/home/zen.nix — Zen Browser, the default browser, sharing one# bookmarks file with Floorp.## This module owns xdg.mimeApps for links and HTML and $BROWSER; the Niri and# Hyprland browser binds launch zen-beta too. Floorp stays installed# (modules/home/floorp.nix); to go back, move those settings to it.## Zen is not in nixpkgs, so the package comes from the community flake# (inputs.zen-browser, pinned in flake.nix). `packages.default` is the general# release channel — the binary is literally `zen-beta` and versions carry a `b`,# which is how upstream labels its releases; `twilight` is the nightly.## The profile is written by hand under ~/.zen, for the same reason as Floorp:# Zen's application.ini declares `Profile=zen`, so Gecko reads ~/.zen rather# than anywhere home-manager's Firefox-family modules would look.## Bookmarks are NOT duplicated. The one encrypted export at# secrets/floorp/bookmarks.html (111 links, 19 folders, matching the live Floorp# profile) is declared here a second time under its own name so this module does# not depend on floorp.nix being imported. Edit it once with# `TMPDIR=/dev/shm sops secrets/floorp/bookmarks.html` and both browsers see it.## Prefs live in Nix here, not sops, because nothing in them is private yet —# only the start page and the bookmark-file path. If this grows personal prefs,# move it to secrets/zen/user.js and mirror the sops.secrets block floorp.nix# uses.{ ... }:
lettheme=import../_palette.nix; in{
flake.homeModules.zen= { config, lib, pkgs, inputs, ... }:
letprofile="daemon";
profileDir=".zen/${profile}";
zen= inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default;
bookmarksPath= config.sops.secrets."zen-bookmarks.html".path;
prefs= {
"browser.bookmarks.file"= bookmarksPath;
"browser.bookmarks.restore_default_bookmarks"=false;
"browser.startup.homepage"="https://startpage.daemon-sec.xyz/";
"browser.startup.page"=3; # restore the previous session"browser.aboutwelcome.enabled"=false;
"browser.startup.firstrunSkipsHomepage"=true;
"datareporting.policy.firstRunURL"="";
"toolkit.legacyUserProfileCustomizations.stylesheets"=true;
"ui.systemUsesDarkTheme"=1;
"browser.theme.content-theme"=0;
"browser.theme.toolbar-theme"=0;
"layout.css.prefers-color-scheme.content-override"=0;
"browser.display.use_system_colors"=false;
"browser.display.background_color"= theme.palette.base;
"browser.display.foreground_color"= theme.palette.text;
"browser.display.document_color_use"=0;
"browser.tabs.allow_transparent_browser"=false;
"browser.toolbars.bookmarks.visibility"="newtab";
"browser.urlbar.trimURLs"=false;
"browser.urlbar.suggest.quicksuggest.sponsored"=false;
"browser.newtabpage.activity-stream.showSponsored"=false;
"browser.newtabpage.activity-stream.showSponsoredTopSites"=false;
"browser.newtabpage.activity-stream.feeds.section.topstories"=false;
"browser.newtabpage.activity-stream.default.sites"="";
"browser.ctrlTab.sortByRecentlyUsed"=true;
"browser.download.useDownloadDir"=false; # ask where to save"general.smoothScroll"=true;
"zen.theme.accent-color"= theme.palette.pine;
"zen.theme.content-element-separation"=8;
"zen.theme.use-system-colors"=false;
"zen.theme.essentials-favicon-bg"=false;
"zen.widget.linux.transparency"=false;
"zen.view.grey-out-inactive-windows"=false;
"zen.view.sidebar-expanded.max-width"=260;
"zen.view.sidebar-expanded"=true;
"zen.view.use-single-toolbar"=true;
"zen.view.window.scheme"=0; # dark"zen.view.compact.enable-at-startup"=false;
"zen.urlbar.show-domain-only-in-sidebar"=false;
"zen.urlbar.show-protections-icon"=true;
"zen.urlbar.hide-one-offs"=false;
"zen.urlbar.open-on-startup"=false;
"zen.tabs.rename-tabs"=true;
"zen.workspaces.swipe-actions"=true;
"zen.workspaces.wrap-around-navigation"=true;
"zen.watermark.enabled"=false;
"zen.welcome-screen.seen"=true;
"media.videocontrols.picture-in-picture.enabled"=true;
};
in {
home.packages= [ zen ];
# Zen as the handler for links and HTML. xdg.mimeApps= {
enable=true;
defaultApplications= lib.genAttrs [
"text/html""application/xhtml+xml""x-scheme-handler/http""x-scheme-handler/https""x-scheme-handler/about""x-scheme-handler/unknown" ] (_: [ "zen-beta.desktop" ]);
};
home.sessionVariables.BROWSER="zen-beta";
# The same encrypted export Floorp imports, under its own secret name so# neither module needs the other. sops-nix is happy for two secrets to come# from one sopsFile; they decrypt to separate runtime paths. sops.secrets."zen-bookmarks.html"= {
sopsFile=../../secrets/floorp/bookmarks.html;
format="binary";
};
home.file= {
# Written here rather than left to Zen so the Nix-built profile is the# default one. Trade-off, as with Floorp: profile changes made in Zen's# own profile manager are reverted on the next `nh os switch`.".zen/profiles.ini".text='' [Profile0] Name=${profile} IsRelative=1 Path=${profile} Default=1 [General] StartWithLastProfile=1 Version=2 '';
# browser.places.importBookmarksHTML is deliberately absent: see the# activation script below for why it cannot live in user.js."${profileDir}/user.js".text='' // Managed by modules/home/zen.nix. Zen reads this only at startup. // Bookmark import stays in prefs.js so it happens only once.${lib.concatStringsSep "\n" (lib.mapAttrsToList
(name: value: "user_pref(${builtins.toJSON name}, ${builtins.toJSON value});") prefs)} '';
"${profileDir}/chrome/userChrome.css".text= theme.render (builtins.readFile ./zen/userChrome.css);
"${profileDir}/chrome/userContent.css".text= theme.render (builtins.readFile ./zen/userContent.css);
};
# One-time bookmark import, same mechanism floorp.nix documents.## `browser.places.importBookmarksHTML` is what makes Gecko read# browser.bookmarks.file into the places database. It cannot live in# user.js: the browser consumes it and sets it back to false, but user.js# re-applies every pref at every startup, so the import would run again on# each launch and duplicate all 111 bookmarks. Seeding it into prefs.js# instead, only while the profile has no places.sqlite yet, imports once on# first launch and never again. home.activation.zenSeedBookmarkImport= lib.hm.dag.entryAfter [ "writeBoundary" ] '' zenProfile="$HOME/${profileDir}" zenPrefs="$zenProfile/prefs.js" if [ ! -e "$zenProfile/places.sqlite" ] \ && ! grep -qs 'browser.places.importBookmarksHTML' "$zenPrefs"; then verboseEcho "Zen: seeding the one-time bookmark import in $zenPrefs" if [ -z "''${DRY_RUN:-}" ]; then mkdir -p "$zenProfile" printf '%s\n' 'user_pref("browser.places.importBookmarksHTML", true);' >> "$zenPrefs" fi fi '';
}
;
}