From d78f6693ee382ee3b94bf48f2b0d0034ce2d902b Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 1 Nov 2023 21:36:40 +0100 Subject: [PATCH] firefox: add finalPackage read-only option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- modules/programs/firefox.nix | 46 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 1bcb0307b..5e43316e2 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -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" =