-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1d99f8
commit e72edae
Showing
7 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
imports = [ | ||
./firefox.nix | ||
./librewolf.nix | ||
./smoothfox.nix | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
cfg = config.programs.firefox; | ||
version = | ||
if (config.programs.firefox.package != null) | ||
then "${config.programs.firefox.package.version}" | ||
else "unknown"; | ||
ext = (import ../autogen/firefox).${cfg.betterfox.version}; | ||
in { | ||
options.programs.firefox = { | ||
betterfox = { | ||
enable = lib.mkEnableOption "betterfox support in profiles"; | ||
version = lib.mkOption { | ||
description = "The version of betterfox user.js used"; | ||
type = lib.types.enum (builtins.attrNames (import ../autogen/firefox)); | ||
default = "main"; | ||
}; | ||
}; | ||
profiles = lib.mkOption { | ||
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { | ||
options.betterfox = lib.mkOption { | ||
description = "Setup betterfox user.js in profile"; | ||
type = import ./types.nix { | ||
extracted = ext; | ||
inherit lib; | ||
}; | ||
default = {}; | ||
}; | ||
config = lib.mkIf cfg.betterfox.enable { | ||
settings = config.betterfox.flatSettings; | ||
}; | ||
})); | ||
}; | ||
}; | ||
|
||
config = lib.mkIf (cfg.enable && cfg.betterfox.enable && !(lib.hasPrefix cfg.betterfox.version version)) { | ||
warnings = [ | ||
"Betterfox version ${cfg.betterfox.version} does not match Firefox's (${version})" | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
cfg = config.programs.librewolf; | ||
version = | ||
if (config.programs.librewolf.package != null) | ||
then "${config.programs.librewolf.package.version}" | ||
else "unknown"; | ||
ext = (import ../autogen/librewolf).${cfg.betterfox.version}; | ||
in { | ||
options.programs.librewolf = { | ||
betterfox = { | ||
enable = lib.mkEnableOption "betterfox support in profiles"; | ||
version = lib.mkOption { | ||
description = "The version of betterfox user.js used"; | ||
type = lib.types.enum (builtins.attrNames (import ../autogen/librewolf)); | ||
default = "main"; | ||
}; | ||
}; | ||
settings = lib.mkOption { | ||
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { | ||
options.betterfox = lib.mkOption { | ||
description = "Setup betterfox user.js in settings"; | ||
type = import ./types.nix { | ||
extracted = ext; | ||
inherit lib; | ||
}; | ||
default = {}; | ||
}; | ||
config = lib.mkIf cfg.betterfox.enable { | ||
settings = config.betterfox.flatSettings; | ||
}; | ||
})); | ||
}; | ||
}; | ||
|
||
config = lib.mkIf (cfg.enable && cfg.betterfox.enable && !(lib.hasPrefix cfg.betterfox.version version)) { | ||
warnings = [ | ||
"Betterfox version ${cfg.betterfox.version} does not match Librewolf's (${version})" | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
cfg = config.programs.firefox; | ||
ext = (import ../autogen/smoothfox).${cfg.betterfox.version}; | ||
in { | ||
options.programs.firefox = { | ||
profiles = lib.mkOption { | ||
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { | ||
options.betterfox.smoothfox = lib.mkOption { | ||
description = "Setup betterfox (Smoothfox) user.js in profile"; | ||
type = import ./types.nix { | ||
extracted = ext; | ||
inherit lib; | ||
}; | ||
default = {}; | ||
}; | ||
config = lib.mkIf cfg.betterfox.enable { | ||
settings = config.betterfox.flatSettings; | ||
}; | ||
})); | ||
}; | ||
}; | ||
|
||
options.programs.librewolf = { | ||
profiles = lib.mkOption { | ||
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { | ||
options.betterfox.smoothfox = lib.mkOption { | ||
description = "Setup betterfox (Smoothfox) user.js in profile"; | ||
type = import ./types.nix { | ||
extracted = ext; | ||
inherit lib; | ||
}; | ||
default = {}; | ||
}; | ||
config = lib.mkIf cfg.betterfox.enable { | ||
settings = config.betterfox.flatSettings; | ||
}; | ||
})); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
lib, | ||
extracted, | ||
... | ||
}: let | ||
mapListToAttrs = f: lst: | ||
builtins.listToAttrs (map f lst); | ||
|
||
settingType = setting: | ||
lib.types.submodule ({config, ...}: { | ||
options = { | ||
enable = lib.mkOption { | ||
type = lib.types.bool; | ||
default = setting.enabled; | ||
description = "Enable the ${setting.name} setting"; | ||
}; | ||
value = lib.mkOption { | ||
type = lib.types.anything; | ||
default = setting.enabled; | ||
description = "The value of the ${setting.name} setting"; | ||
}; | ||
flat = lib.mkOption { | ||
type = lib.types.attrsOf lib.types.anything; | ||
description = "Empty attrset in enable=false, the setting and its value otherwise"; | ||
readOnly = true; | ||
}; | ||
}; | ||
config = { | ||
flat = | ||
if config.enable | ||
then {"${setting.name}" = config.value;} | ||
else {}; | ||
}; | ||
}); | ||
|
||
settingOption = setting: | ||
lib.nameValuePair setting.name | ||
(lib.mkOption { | ||
description = "Control the ${setting.name} setting"; | ||
type = settingType setting; | ||
default = {}; | ||
}); | ||
|
||
subsectionType = name: sub: | ||
lib.types.submodule ({config, ...}: { | ||
options = | ||
{ | ||
enable = lib.mkEnableOption "settings for ${name}"; | ||
flatSettings = lib.mkOption { | ||
description = "Flat attrset of all settings in subsection ${name} enabled"; | ||
type = lib.types.attrsOf lib.types.anything; | ||
readOnly = true; | ||
}; | ||
} | ||
// mapListToAttrs settingOption sub.settings; | ||
config = { | ||
enable = lib.mkDefault true; | ||
flatSettings = | ||
if config.enable | ||
then | ||
builtins.foldl' (x: y: x // y) {} | ||
(map (setting: config.${setting.name}.flat) sub.settings) | ||
else {}; | ||
}; | ||
}); | ||
subsectionOption = name: sub: | ||
lib.mkOption { | ||
description = "${name}: ${sub.meta.title}"; | ||
type = subsectionType name sub; | ||
default = {}; | ||
}; | ||
|
||
sectionType = name: section: let | ||
subsections = builtins.removeAttrs section ["meta"]; | ||
in | ||
lib.types.submodule ({config, ...}: { | ||
options = | ||
{ | ||
enable = lib.mkOption { | ||
description = "setting for ${name}"; | ||
type = lib.types.bool; | ||
}; | ||
flatSettings = lib.mkOption { | ||
description = "Flat attrset of all settings in section ${name} enabled"; | ||
type = lib.types.attrsOf lib.types.anything; | ||
readOnly = true; | ||
}; | ||
} | ||
// lib.mapAttrs subsectionOption subsections; | ||
config = { | ||
flatSettings = | ||
if config.enable | ||
then | ||
builtins.foldl' (x: y: x // y) {} | ||
(lib.mapAttrsToList (name: _: config.${name}.flatSettings) subsections) | ||
else {}; | ||
}; | ||
}); | ||
sectionOption = name: section: | ||
lib.mkOption { | ||
description = "${name}: ${section.meta.title}"; | ||
type = sectionType name section; | ||
default = {}; | ||
}; | ||
enableSection = name: _: {config, ...}: { | ||
"${name}".enable = lib.mkDefault config.enableAllSections; | ||
}; | ||
|
||
type = lib.types.submodule ({config, ...}: { | ||
options = | ||
{ | ||
enable = lib.mkEnableOption "Betterfox settings"; | ||
enableAllSections = lib.mkEnableOption "Enable all sections by default"; | ||
flatSettings = lib.mkOption { | ||
description = "Flat attrset of all settings enabled"; | ||
type = lib.types.attrsOf lib.types.anything; | ||
readOnly = true; | ||
}; | ||
} | ||
// lib.mapAttrs sectionOption extracted; | ||
config = { | ||
flatSettings = | ||
if config.enable | ||
then | ||
builtins.foldl' (x: y: x // y) {} | ||
(lib.mapAttrsToList (name: _: config.${name}.flatSettings) extracted) | ||
else {}; | ||
}; | ||
imports = lib.mapAttrsToList enableSection extracted; | ||
}); | ||
in | ||
type |