Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/home-manager/all-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
./dunst.nix
./element-desktop.nix
./fcitx5.nix
./firefox.nix
./firefox
./fish.nix
./foot.nix
./freetube.nix
Expand Down
136 changes: 0 additions & 136 deletions modules/home-manager/firefox.nix

This file was deleted.

25 changes: 25 additions & 0 deletions modules/home-manager/firefox/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ catppuccinLib }:
{ lib, ... }:

let
mkFirefoxModule =
args:

lib.modules.importApply ./mkFirefoxModule.nix (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the reason for separating this out into a new file so that it could be imported & used elsewhere? (even if it's external)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's more so to just keep each file simple

It felt kinda weird having such a massive function, and practically two cases of setting config. This is as opposed to now where mkFirefoxModule is written mostly just like a regular module, and the generation magic happens in this default.nix

Upstream home-manager does the same thing

args
// {
inherit catppuccinLib;
}
);
in

{
imports = map mkFirefoxModule [
{ name = "firefox"; }
{
name = "librewolf";
prettyName = "LibreWolf"; # W in LibreWolf is uppercase
}
{ name = "floorp"; }
];
}
132 changes: 132 additions & 0 deletions modules/home-manager/firefox/mkFirefoxModule.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
catppuccinLib,

name,
prettyName ? null,
hmModulePath ? [
"programs"
name
],
}:
{ config, lib, ... }:

let
inherit (lib)
attrNames
const
foldl'
genAttrs
hasAttr
importJSON
toSentenceCase
optional
mkIf
mkOption
getAttrFromPath
setAttrByPath
types
;

getAttrStringFromPath = lib.concatStringsSep ".";

inherit (config.catppuccin) sources;
themes = importJSON "${sources.firefox}/themes.json";

cfg = getAttrFromPath modulePath config;
firefoxCfg = getAttrFromPath hmModulePath config;

modulePath = [
"catppuccin"
name
];
prettyName' = if prettyName == null then toSentenceCase name else prettyName;

optionsModule = {
options =
catppuccinLib.mkCatppuccinOption {
inherit name;
accentSupport = true;
}
// {
force = mkOption {
type = types.bool;
default = false;
description = "Forcibly override any existing configuration for Firefox Color.";
example = true;
};
};
};

catppuccinProfilesSubmodule = {
imports = [ optionsModule ];

config = lib.mapAttrs (lib.const lib.mkDefault) {
inherit (cfg)
enable
flavor
accent
force
;
};
};

catppuccinOptions = setAttrByPath modulePath (
lib.mkOption {
type = lib.types.submodule {
imports = [ optionsModule ];

options = {
profiles = mkOption {
type = types.attrsOf (types.submodule catppuccinProfilesSubmodule);
default = genAttrs (attrNames firefoxCfg.profiles) (const { });
defaultText = "<profiles declared in `${getAttrStringFromPath hmModulePath}.profiles`>";
description = "Catppuccin settings for ${prettyName'} profiles.";
};
};
};
default = { };
description = "Catppuccin settings for ${prettyName'}.";
}
);

firefoxProfilesSubmodule =
{ name, ... }:

let
profile = cfg.profiles.${name} or { enable = false; };
in

{
config = mkIf profile.enable {
extensions = {
settings."[email protected]" = {
inherit (profile) force;
settings = {
firstRunDone = true;
theme = themes.${profile.flavor}.${profile.accent};
};
};
};
};
};

homeOptions = setAttrByPath hmModulePath {
profiles = mkOption {
type = types.attrsOf (types.submodule firefoxProfilesSubmodule);
};
};
in

{
options = catppuccinOptions // homeOptions;

config = {
warnings = foldl' (
acc: name:
acc
++
optional (!(hasAttr name firefoxCfg.profiles))
"${prettyName'} profile '${name}' is defined in '${getAttrStringFromPath modulePath}', but not '${getAttrStringFromPath hmModulePath}'. This will have no effect."
) [ ] (attrNames cfg.profiles);
};
}
Loading