{ config, lib, pkgs, ... }: with lib; let inherit (pkgs.stdenv.hostPlatform) isDarwin; cfg = config.programs.floorp; jsonFormat = pkgs.formats.json {}; floorpConfigPath = if isDarwin then "Library/Application Support/Floorp" else "${config.home.homeDirectory}/.floorp"; profilesPath = if isDarwin then "${floorpConfigPath}/Profiles" else floorpConfigPath; # The extensions path shared by all profiles; will not be supported # by future Floorp versions. extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; 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; 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 (floorpBookmarksFile bookmarks); "browser.places.importBookmarksHTML" = true; } // prefs; in '' // Generated by Home Manager. ${concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${userPrefValue value}); '') prefs')} ${extraPrefs} ''; mkContainersJson = containers: let containerToIdentity = _: container: { userContextId = container.id; name = container.name; icon = container.icon; color = container.color; public = true; }; in '' ${builtins.toJSON { version = 4; lastUserContextId = elemAt (mapAttrsToList (_: container: container.id) containers) 0; identities = mapAttrsToList containerToIdentity containers; }} ''; floorpBookmarksFile = 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}
''; itemToHTMLOrRecurse = indentLevel: item: if item ? "url" then bookmarkToHTML indentLevel item else directoryToHTML indentLevel item; allItemsToHTML = indentLevel: bookmarks: lib.concatStringsSep "\n" (map (itemToHTMLOrRecurse indentLevel) bookmarks); bookmarkEntries = allItemsToHTML 1 bookmarks; in pkgs.writeText "floorp-bookmarks.html" ''
${bookmarkEntries}