1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-25 02:10:57 +01:00

firefox: add bookmarks support

Generate bookmarks html file and hook it up in user.js.
This commit is contained in:
Emil Karlson 2021-09-29 09:39:17 +03:00 committed by Robert Helgesson
parent 095f3e32ae
commit e0a87d75e9
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 131 additions and 8 deletions

View file

@ -40,15 +40,50 @@ let
profilesIni = generators.toINI { } profiles;
mkUserJs = prefs: extraPrefs: ''
// Generated by Home Manager.
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)}
${concatStrings (mapAttrsToList (name: value: ''
user_pref("${name}", ${builtins.toJSON value});
'') prefs')}
${extraPrefs}
'';
${extraPrefs}
'';
firefoxBookmarksFile = bookmarks:
let
escapeXML = replaceStrings [ ''"'' "'" "<" ">" "&" ] [
"&quot;"
"&apos;"
"&lt;"
"&gt;"
"&amp;"
];
mapper = _: entry: ''
<DT><A HREF="${escapeXML entry.url}" ADD_DATE="0" LAST_MODIFIED="0"${
lib.optionalString (entry.keyword != null)
" SHORTCUTURL=\"${escapeXML entry.keyword}\""
}>${escapeXML entry.name}</A>
'';
bookmarksEntries = lib.attrsets.mapAttrsToList mapper bookmarks;
in pkgs.writeText "firefox-bookmarks.html" ''
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks Menu</H1>
<DL><p>
${concatStrings bookmarksEntries}
</p></DL>
'';
in {
meta.maintainers = [ maintainers.rycee ];
@ -197,6 +232,45 @@ in {
'';
};
bookmarks = mkOption {
type = types.attrsOf (types.submodule ({ config, name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Bookmark name.";
};
keyword = mkOption {
type = types.nullOr types.str;
default = null;
description = "Bookmark search keyword.";
};
url = mkOption {
type = types.str;
description = "Bookmark url, use %s for search terms.";
};
};
}));
default = { };
example = literalExample ''
{
wikipedia = {
keyword = "wiki";
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
};
"kernel.org" = {
url = "https://www.kernel.org";
};
}
'';
description = ''
Preloaded bookmarks. Note, this may silently overwrite any
previously existing bookmarks!
'';
};
path = mkOption {
type = types.str;
default = name;
@ -298,7 +372,8 @@ in {
"${profilesPath}/${profile.path}/user.js" =
mkIf (profile.settings != { } || profile.extraConfig != "") {
text = mkUserJs profile.settings profile.extraConfig;
text =
mkUserJs profile.settings profile.extraConfig profile.bookmarks;
};
"${profilesPath}/${profile.path}/extensions" =