{ config, lib, pkgs, ... }: with lib; let cfg = config.programs.mullvad-browser; jsonFormat = pkgs.formats.json { }; dataConfigPath = ".mullvad/mullvadbrowser"; profilesPath = dataConfigPath; # The extensions path shared by all profiles; will not be supported # by future Firefox versions. extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; profiles = flip mapAttrs' cfg.profiles (_: profile: nameValuePair "Profile${toString profile.id}" { Name = profile.name; Path = profile.path; IsRelative = 1; Default = if profile.isDefault then 1 else 0; }) // { General = { StartWithLastProfile = 1; }; }; profilesIni = generators.toINI { } profiles; userPrefValue = pref: builtins.toJSON (if isBool pref || isInt pref || isString pref then pref else builtins.toJSON pref); mkUserJs = prefs: extraPrefs: bookmarks: let prefs' = lib.optionalAttrs ([ ] != bookmarks) { "browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks); "browser.places.importBookmarksHTML" = true; } // prefs; in '' // Generated by Home Manager. ${concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${userPrefValue value}); '') prefs')} ${extraPrefs} ''; mkProfileBin = profile: let name = "mullvad-browser-${profile}"; scriptBin = pkgs.writeScriptBin name '' mullvad-browser -P "${profile}" --name="${name}" $@ ''; desktopFile = pkgs.makeDesktopItem { inherit name; exec = "${scriptBin}/bin/${name} %U"; icon = "mullvad-browser"; extraConfig.StartupWMClass = name; desktopName = "Mullvad Browser (${profile})"; genericName = "Web Browser"; categories = [ "Network" "WebBrowser" "Security" ]; }; in pkgs.runCommand name { } '' mkdir -p $out/{bin,share} cp -r ${scriptBin}/bin/${name} $out/bin/${name} cp -r ${desktopFile}/share/applications $out/share/applications ''; firefoxBookmarksFile = bookmarks: let indent = level: lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level)); bookmarkToHTML = indentLevel: bookmark: '' ${indent indentLevel}
${allItemsToHTML (indentLevel + 1) directory.bookmarks} ${indent indentLevel}
${bookmarkEntries}