diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 68a9ffd8..83303f68 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -42,7 +42,7 @@ let mkUserJs = prefs: extraPrefs: bookmarks: let - prefs' = lib.optionalAttrs ({ } != bookmarks) { + prefs' = lib.optionalAttrs ([ ] != bookmarks) { "browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks); "browser.places.importBookmarksHTML" = true; } // prefs; @@ -58,13 +58,36 @@ let firefoxBookmarksFile = bookmarks: let - mapper = _: entry: '' -
${escapeXML entry.name} - ''; - bookmarksEntries = lib.attrsets.mapAttrsToList mapper bookmarks; + indent = level: + lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level)); + + bookmarkToHTML = indentLevel: bookmark: + '' + ${indent indentLevel}
${escapeXML bookmark.name}''; + + directoryToHTML = indentLevel: directory: '' + ${indent indentLevel}

${escapeXML directory.name}

+ ${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 + (if isAttrs bookmarks then lib.attrValues bookmarks else bookmarks); in pkgs.writeText "firefox-bookmarks.html" ''