{ config, lib, pkgs, ... }: with lib; let inherit (pkgs.stdenv.hostPlatform) isDarwin; cfg = config.programs.firefox; mozillaConfigPath = if isDarwin then "Library/Application Support/Mozilla" else ".mozilla"; firefoxConfigPath = if isDarwin then "Library/Application Support/Firefox" else "${mozillaConfigPath}/firefox"; profilesPath = if isDarwin then "${firefoxConfigPath}/Profiles" else firefoxConfigPath; # The extensions path shared by all profiles; will not be supported # by future Firefox versions. extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; extensionsEnvPkg = pkgs.buildEnv { name = "hm-firefox-extensions"; paths = cfg.extensions; }; profiles = flip mapAttrs' cfg.profiles (_: profile: nameValuePair "Profile${toString profile.id}" { Name = profile.name; Path = if isDarwin then "Profiles/${profile.path}" else profile.path; IsRelative = 1; Default = if profile.isDefault then 1 else 0; }) // { General = { StartWithLastProfile = 1; }; }; profilesIni = generators.toINI { } profiles; 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}", ${builtins.toJSON value}); '') prefs')} ${extraPrefs} ''; firefoxBookmarksFile = bookmarks: let mapper = _: entry: ''
${concatStrings bookmarksEntries}