firefox: add finalPackage read-only option

When a user references config.programs.firefox.package in her/his
configuration, s·he will get a different path than what is in the
$PATH variable. To make it possible to get the same path, this commit
introduces the finalPackage read-only option.
This commit is contained in:
Damien Cassou 2023-11-01 21:36:40 +01:00 committed by Robert Helgesson
parent 691cbcc03a
commit d78f6693ee
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -152,6 +152,27 @@ let
'' + concatStringsSep "\n" (mapAttrsToList mkMsg duplicates);
});
wrapPackage = package:
let
# The configuration expected by the Firefox wrapper.
fcfg = { enableGnomeExtensions = cfg.enableGnomeExtensions; };
# A bit of hackery to force a config into the wrapper.
browserName =
package.browserName or (builtins.parseDrvName package.name).name;
# The configuration expected by the Firefox wrapper builder.
bcfg = setAttrByPath [ browserName ] fcfg;
in if package == null then
null
else if isDarwin then
package
else if versionAtLeast config.home.stateVersion "19.09" then
package.override (old: { cfg = old.cfg or { } // fcfg; })
else
(pkgs.wrapFirefox.override { config = bcfg; }) package { };
in {
meta.maintainers = [ maintainers.rycee maintainers.kira-bruneau ];
@ -203,6 +224,12 @@ in {
'';
};
finalPackage = mkOption {
type = with types; nullOr package;
readOnly = true;
description = "Resulting Firefox package.";
};
profiles = mkOption {
type = types.attrsOf (types.submodule ({ config, name, ... }: {
options = {
@ -620,24 +647,9 @@ in {
its example for how to do this.
'';
home.packages = let
# The configuration expected by the Firefox wrapper.
fcfg = { enableGnomeExtensions = cfg.enableGnomeExtensions; };
programs.firefox.finalPackage = wrapPackage cfg.package;
# A bit of hackery to force a config into the wrapper.
browserName = cfg.package.browserName or (builtins.parseDrvName
cfg.package.name).name;
# The configuration expected by the Firefox wrapper builder.
bcfg = setAttrByPath [ browserName ] fcfg;
package = if isDarwin then
cfg.package
else if versionAtLeast config.home.stateVersion "19.09" then
cfg.package.override (old: { cfg = old.cfg or { } // fcfg; })
else
(pkgs.wrapFirefox.override { config = bcfg; }) cfg.package { };
in lib.optional (cfg.package != null) package;
home.packages = lib.optional (cfg.finalPackage != null) cfg.finalPackage;
home.file = mkMerge ([{
"${firefoxConfigPath}/profiles.ini" =