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

Open
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 2 times, most recently from d7be395 to 849183a Compare January 7, 2025 03:07
// {
finalPackage = lib.mkOption {
type = lib.types.package;
readOnly = true;
Copy link
Member

Choose a reason for hiding this comment

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

perhpas we should mark this as visible = false such that the search won't have this come up?

Suggested change
readOnly = true;
readOnly = true;
visible = false;

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.

4 participants