Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(home-manager): add support for firefox-based browsers #451

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anomalocaridid
Copy link
Contributor

@Anomalocaridid Anomalocaridid commented Jan 5, 2025

This adds support for Firefox-based browsers that have settings implemented by home manager's internal mkFirefoxModule function. This should hopefully also make it easy to add support for other Firefox-based browsers in the future, although changes may have to be made if any special cases arise.

Currently, this only implements support for the three web browsers I saw that use mkFireFoxModule, namely:

  • Firefox
  • Floorp
  • Librewolf

I added a finalPackage option to each of their modules because I overrode extraPrefsFiles to try to immutably set the theme addon.

I was not sure how to best share the common logic between the browsers, so I put them all in one file, firefox.nix. The common logic seemed like it would be too long to include in catppuccinLib and currently the only differences between the browsers' modules are the name of the browser itself.

Also, manually enabling the theme is needed in some cases, such as when switching between Catppuccin themes and in Floorp's case, it is needed even on a clean setup for some reason. Unfortunately, I am not sure if there is a way to address this.

Furthermore, in case it is helpful, I had to use the old tag from catppuccin/firefox because otherwise this would need to access the GitHub release artifacts, although those are the same files anyways. I assumed this would be fine because the GTK module appears to do something similar.

@Anomalocaridid Anomalocaridid force-pushed the firefox branch 3 times, most recently from ef006cf to 01fe782 Compare January 5, 2025 04:17
Comment on lines 117 to 57
profiles.default.extensions = [
# Only package desired theme addon to not pollute themes list
# and to avoid flooding the user with extension added notifications
# Code adapted from `buildFirefoxXpiAddon` from
# https://github.com/nix-community/nur-combined/blob/master/repos/rycee/pkgs/firefox-addons/default.nix
(pkgs.runCommand "catppuccin-firefox" { } ''
dst="$out/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
mkdir -p "$dst"
install -v -m644 "${sources.firefox}/catppuccin_${cfg.flavor}_${cfg.accent}.xpi" "$dst/${addonId}.xpi"
'')
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an option for defining the profiles to install it would be nice, instead of just assuming the profile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added a profiles option that takes a list of profiles, defaulting with [ "default" ].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see your comment here. I don't think there should be a default value, also, the config needs update to install in all profiles, it is currently just installing on the default profile still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the config needs update to install in all profiles, it is currently just installing on the default profile still

My bad, thank you for catching that.

Comment on lines 122 to 126
(pkgs.runCommand "catppuccin-firefox" { } ''
dst="$out/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
mkdir -p "$dst"
install -v -m644 "${sources.firefox}/catppuccin_${cfg.flavor}_${cfg.accent}.xpi" "$dst/${addonId}.xpi"
'')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to move this to the package rather than here. Maybe we can use split outputs? Or a scope?

Copy link
Contributor Author

@Anomalocaridid Anomalocaridid Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to move it to the package using split outputs. I have never needed to use split outputs or package scopes before, so I am not sure if the way I did it is the best.

I made an output for each addon in the form ${flavor}_${accent}. (e.g. mocha_mauve). I could not leave out out without causing an error, so I kept it. I was not sure what to put in it, so $out is just an empty directory.


# Each Firefox addon has an ID used to refer to it in the config
# Unfortunately, these addons just use randomly generated ones
addonIds = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a review, I'm just very impressed (and sorry) that you sorted through all of these. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My pleasure! I am more than happy to go to such lengths for declarative configuration.

@getchoo getchoo added this to the 2.0.0 milestone Jan 5, 2025
@Anomalocaridid Anomalocaridid force-pushed the firefox branch 3 times, most recently from 275b6b3 to 48926e6 Compare January 6, 2025 01:44
fetchFromGitHub,
lib,
}:
buildCatppuccinPort (finalAttrs: rec {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make it a rec attribute set if there is finalAttrs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to access addonIds to make outputs and referencing it through finalAttrs there caused infinite recursion. I also assumed it would be better to use finalAttrs where I could rather than just using rec for everything.

Is there a better way to accomplish this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. I think you can just put addonIds in a let in and then inherit it in passthru then you can remove rec and use it to make outputs using the variable. I think this is a better way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I also removed finalAttrs because that was the only thing it was used for.

@Anomalocaridid Anomalocaridid force-pushed the firefox branch 3 times, most recently from 849183a to 2d97f2f Compare January 7, 2025 03:11
@bbigras
Copy link

bbigras commented Feb 19, 2025

Note that there's nix-community/home-manager@27ffa35 now.

I'm able to use extensions.settings."[email protected]".settings = builtins.fromJSON (builtins.readFile ./firefox-color.json);

@Anomalocaridid
Copy link
Contributor Author

Note that there's nix-community/home-manager@27ffa35 now.

I'm able to use extensions.settings."[email protected]".settings = builtins.fromJSON (builtins.readFile ./firefox-color.json);

Neat! That would probably make things quite a bit simpler and reduce the risk of the extensions becoming out of date in the future. Albeit at the cost of adding IFD.

However, would it necessitate packaging Firefox Color in this flake? Or could it just be set without installing the extension and then anyone that wants to use it could use the NUR to install Firefox Color themselves?

Also, where is firefox-color.json from? I cannot find it in catppuccin/firefox and I am not sure where else to look.

@bbigras
Copy link

bbigras commented Feb 20, 2025

If I understand correctly, the new home-manager Firefox extension setting forces Firefox to store the extension settings as JSON file (instead of indexdb).

However, would it necessitate packaging Firefox Color in this flake?

I just tested, and it's fine to create the ~/.mozilla/firefox/default/browser-extension-data/[email protected]/storage.js file even if the extension is not installed. If you install the extension, the file is read. Not sure what happens if the extension has a bunch of new settings to store.

Also, where is firefox-color.json from?

I just took ~/.mozilla/firefox/default/browser-extension-data/[email protected]/storage.js

One thing to note is that, with the new home-manager setting, I get some Existing file errors. Maybe I should just use home-manager.backupFileExtension but it's not working in my nix-config for some reason.

While I like the new home-manager setting, I can't use it for ublock since I often need to add exceptions and I don't want them overwritten.

@Anomalocaridid
Copy link
Contributor Author

I just tested, and it's fine to create the ~/.mozilla/firefox/default/browser-extension-data/[email protected]/storage.js file even if the extension is not installed. If you install the extension, the file is read. Not sure what happens if the extension has a bunch of new settings to store.

Thanks for testing it! So this approach could be viable even if users have to manually install Firefox Color themselves.

I just took ~/.mozilla/firefox/default/browser-extension-data/[email protected]/storage.js

Using that directly would probably not be a good idea. However, we could use the palette to manually set the colors to have an equivalent effect like how the tty and fzf ports are implemented.

One thing to note is that, with the new home-manager setting, I get some Existing file errors. Maybe I should just use home-manager.backupFileExtension but it's not working in my nix-config for some reason.

Somewhat off-topic, but I think home-manager.backupFileExtension needs to be set in the current generation before it has any effect.

With all that said, I think this port is blocked on a few questions that I need help in answering:

  • Should we use the "legacy" themes or switch to Firefox Color?
    • The "legacy" themes are potentially at risk of becoming outdated at some point since they technically aren't being maintained (i.e. if something they rely on gets deprecated or removed from Firefox), but this probably will not be a problem for a while. However, we would not have to worry about how to handle dependencies on non-Catppuccin Firefox extensions.
    • Firefox Color would result in another module depending on the palette and having to manually sync colors if the themes change going forward, like we currently do with the fzf and tty ports. However, it would also give users the opportunity to override any colors they want. In this case, we would probably need to do one of two things:
      • Make users install Firefox Color themselves. (Which would be slightly inconvenient)
      • Package Firefox Color ourselves. (Which may or may not be out of scope)
    • Since it is now feasible to support other extensions like, say, Dark Reader and Stylus, if we want to eventually do so, we would still need to figure out how to handle reliance on non-Catppuccin Firefox extensions anyways.
  • Since the changes to firefox.extensions will need to be supported regardless of what approach we use, would it need to be polyfilled for older versions of Home Manager? If so, how?
    • This may not be a concern if we go the Firefox Color route since we would have to rely on the changes anyways.

@Anomalocaridid Anomalocaridid marked this pull request as draft February 20, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants