From 73641e492c2d761676110d52eb15607b308b5e70 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 18 Aug 2019 10:57:30 +0200 Subject: [PATCH] firefox: use wrapped package This makes the programs.firefox.package option take a pre-wrapped Firefox package as value if state version is set to "19.09" or later. This should make the Firefox module work with a wider range of Firefox packages. --- doc/release-notes/rl-1909.xml | 23 ++++++++++++ modules/programs/firefox.nix | 36 ++++++++++++------- tests/default.nix | 1 + tests/modules/programs/firefox/default.nix | 4 +++ .../firefox/profile-settings-expected-user.js | 6 ++++ .../programs/firefox/profile-settings.nix | 24 +++++++++++++ .../programs/firefox/state-version-19_09.nix | 17 +++++++++ 7 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 tests/modules/programs/firefox/default.nix create mode 100644 tests/modules/programs/firefox/profile-settings-expected-user.js create mode 100644 tests/modules/programs/firefox/profile-settings.nix create mode 100644 tests/modules/programs/firefox/state-version-19_09.nix diff --git a/doc/release-notes/rl-1909.xml b/doc/release-notes/rl-1909.xml index 6addc0c5..3094debc 100644 --- a/doc/release-notes/rl-1909.xml +++ b/doc/release-notes/rl-1909.xml @@ -9,4 +9,27 @@ This is the current unstable branch and the information in this section is therefore not final. + +
+ State Version Changes + + + The state version in this release includes the changes below. These changes + are only active if the option is set to + "19.09" or later. + + + + + + The option now expects a wrapped + Firefox package and defaults to pkgs.firefox. + + + +
diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index c43781a7..e47bec3e 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -45,9 +45,16 @@ in package = mkOption { type = types.package; - default = pkgs.firefox-unwrapped; - defaultText = "pkgs.firefox-unwrapped"; - description = "The unwrapped Firefox package to use."; + default = + if versionAtLeast config.home.stateVersion "19.09" + then pkgs.firefox + else pkgs.firefox-unwrapped; + defaultText = "pkgs.firefox"; + description = '' + The Firefox package to use. If state version ≥ 19.09 then + this should be a wrapped Firefox package. For earlier state + versions it should be an unwrapped Firefox package. + ''; }; extensions = mkOption { @@ -220,21 +227,26 @@ in home.packages = let - # A bit of hackery to force a config into the wrapper. - browserName = cfg.package.browserName - or (builtins.parseDrvName cfg.package.name).name; - - fcfg = setAttrByPath [browserName] { + # The configuration expected by the Firefox wrapper. + fcfg = { enableAdobeFlash = cfg.enableAdobeFlash; enableGoogleTalkPlugin = cfg.enableGoogleTalk; icedtea = cfg.enableIcedTea; }; - wrapper = pkgs.wrapFirefox.override { - config = fcfg; - }; + # 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 versionAtLeast config.home.stateVersion "19.09" + then cfg.package.override { cfg = fcfg; } + else (pkgs.wrapFirefox.override { config = bcfg; }) cfg.package { }; in - [ (wrapper cfg.package { }) ]; + [ package ]; home.file = mkMerge ( [{ diff --git a/tests/default.nix b/tests/default.nix index 29b02eeb..3d0d23b9 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -35,6 +35,7 @@ import nmt { } // import ./modules/misc/pam // import ./modules/misc/xsession + // import ./modules/programs/firefox // import ./modules/systemd ) // import ./modules/home-environment diff --git a/tests/modules/programs/firefox/default.nix b/tests/modules/programs/firefox/default.nix new file mode 100644 index 00000000..6612a9ac --- /dev/null +++ b/tests/modules/programs/firefox/default.nix @@ -0,0 +1,4 @@ +{ + firefox-profile-settings = ./profile-settings.nix; + firefox-state-version-19_09 = ./state-version-19_09.nix; +} diff --git a/tests/modules/programs/firefox/profile-settings-expected-user.js b/tests/modules/programs/firefox/profile-settings-expected-user.js new file mode 100644 index 00000000..0edd47b9 --- /dev/null +++ b/tests/modules/programs/firefox/profile-settings-expected-user.js @@ -0,0 +1,6 @@ +// Generated by Home Manager. + +user_pref("general.smoothScroll", false); + + + diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix new file mode 100644 index 00000000..45465b1d --- /dev/null +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -0,0 +1,24 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.firefox = { + enable = true; + profiles.test.settings = { + "general.smoothScroll" = false; + }; + }; + + nmt.script = '' + assertFileRegex \ + home-path/bin/firefox \ + MOZ_APP_LAUNCHER + + assertFileContent \ + home-files/.mozilla/firefox/test/user.js \ + ${./profile-settings-expected-user.js} + ''; + }; +} diff --git a/tests/modules/programs/firefox/state-version-19_09.nix b/tests/modules/programs/firefox/state-version-19_09.nix new file mode 100644 index 00000000..0c930961 --- /dev/null +++ b/tests/modules/programs/firefox/state-version-19_09.nix @@ -0,0 +1,17 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "19.09"; + + programs.firefox.enable = true; + + nmt.script = '' + assertFileRegex \ + home-path/bin/firefox \ + MOZ_APP_LAUNCHER + ''; + }; +}