nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.25k stars 1.68k forks source link

Firefox: Import HTML file of bookmarks #4885

Open D3vil0p3r opened 5 months ago

D3vil0p3r commented 5 months ago

Description

For users having hundreds of bookmarks to import can be very heavy to write them manually in nix file. Can you add the possibility in firefox module for HM to import HTML bookmark file in Firefox?

rebeccasaurus commented 2 months ago

I think I may have found a solution for this! A minimal example:

    programs.firefox = {
      enable = true;

      profiles.bex = {
        settings = {
          "browser.bookmarks.file" = "/home/bex/.dotfiles/nixos/modules/home-manager/firefox/bookmarks.html";
          "browser.places.importBookmarksHTML" = true;
        };
      };
    };

I'm assuming there's a better way of getting the user's home directory in Nix, but I had some trouble and the absolute path worked. (I'm very new at Nix/NixOS/Home Manager.)

Edit: I'm assuming this will replace your bookmarks on every rebuild, so you have to be careful to re-export them if any changes are made.

sumnerevans commented 2 months ago

You can use config.home.homeDirectory to reference the user's home directory.

You could probably also reference the bookmarks path directly like:

"browser.bookmarks.file" = ./relative/path/to/bookmarks.html;

which will put it into the nix store (which you may or may not want). Also, Firefox might get mad if it can't write to the bookmarks file.

rebeccasaurus commented 2 months ago

Ah, I'll give that one a go, thanks!

As for the relative path, it actually puts it in the store with a full path, if you skip the quotes around the path. The problem there is that the generated user.js then contains something like this:

user_pref("browser.bookmarks.file", "\"/nix/store/3rbwiydh7hwykzwiyq3wsf34n4zhyvni-bookmarks.html\"");

Notice the escaped quotes within quotes, doesn't work, Firefox refuses to load them. I'm guessing this is some bug in the programs.firefox-module of Home Manager, will look in to it some more and add a bug report for it.