about summary refs log tree commit diff stats
path: root/home-manager/firefox/default.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--home-manager/firefox/default.nix152
1 files changed, 82 insertions, 70 deletions
diff --git a/home-manager/firefox/default.nix b/home-manager/firefox/default.nix
index af627a21..88fad227 100644
--- a/home-manager/firefox/default.nix
+++ b/home-manager/firefox/default.nix
@@ -5,17 +5,32 @@
   lib,
   stdenv,
   strip_js_comments,
+  generate_extensions,
   user_js,
+  system,
   ...
 }: let
-  user_js_override = "./settings/override.js";
-  user_js = pkgs.runCommand "user.js" {} ''
-    mkdir $out;
-    ${strip_js_comments}/bin "${user_js}/user.js" > $out/user.js;
-    cat ${user_js_override} >> $out/user.js;
-    sed 's/user_pref(\(.*\)",\(.*\));/\1" = \2;/' $out/user.js > $out/user.nix;
+  userChrome = builtins.readFile ./chrome/userChrome.css;
+
+  user_js_override = pkgs.writeText "user.override.js" (builtins.readFile ./settings/override.js);
+  user_js_nix = pkgs.runCommand "user.js" {} ''
+        mkdir $out;
+        cat "${user_js}/user.js" > $out/user.js;
+        cat "${user_js_override}" >> $out/user.js;
+
+        "${strip_js_comments.app.${system}.default.program}" $out/user.js > $out/user_clean.js;
+    #    echo "{" > $out/user.nix.tmp
+    #    sed 's/user_pref(\(.*\)",\(.*\));/\1" = \2;/' $out/user_clean.js >> $out/user.nix.tmp;
+    #    echo "}" >> $out/user.nix.tmp
+    #    awk '!/"_user.js.parrot"/' $out/user.nix.tmp >> $out/user.nix; # delete duplicate keys
   '';
 
+  extensions = builtins.map buildFirefoxXpiAddon (
+    lib.attrValues (
+      lib.importJSON ./settings/extensions.json
+    )
+  );
+
   # source: https://gitlab.com/rycee/nur-expressions/-/blob/master/pkgs/firefox-addons/default.nix
   buildFirefoxXpiAddon = {
     pname,
@@ -23,13 +38,13 @@
     addonId,
     url,
     sha256,
-    meta,
+#meta,
     ...
   }:
-    builtins.stdenv.mkDerivation {
+    pkgs.stdenv.mkDerivation {
       name = "${pname}-${version}";
 
-      inherit meta;
+#inherit meta;
 
       src = builtins.fetchurl {inherit url sha256;};
 
@@ -43,68 +58,64 @@
       '';
     };
 
-  settings =
-    pkgs.lib.recursiveUpdate
-    {
-      # Allow my custom css
-      "toolkit.legacyUserProfileCustomizations.stylesheets" = true;
-
-      # might improve performance TODO
-      "gfx.webrender.all" = true;
-
-      # disable updates (pretty pointless with nix)
-      "extensions.update.autoUpdateDefault" = false;
-      "extensions.update.enabled" = false;
-      "app.update.channel" = "default";
-
-      "browser.ctrlTab.recentlyUsedOrder" = false;
-
-      "browser.download.useDownloadDir" = true;
-      "browser.download.dir" = "${config.user.soisha.home}/media/downloads";
-      "browser.download.folderList" = 2; # TODO
-      "browser.download.viewableInternally.typeWasRegistered.svg" = true;
-      "browser.download.viewableInternally.typeWasRegistered.webp" = true;
-      "browser.download.viewableInternally.typeWasRegistered.xml" = true;
-
-      # TODO what does this do?
-      "browser.search.widget.inNavBar" = true;
-
-      "browser.shell.checkDefaultBrowser" = false;
-      "browser.tabs.loadInBackground" = true;
-      "browser.urlbar.placeholderName" = "Brave";
-
-      "general.autoScroll" = true;
-
-      # Set the tabs and bookmarks
-      "browser.tabs.inTitlebar" = 1;
-      "browser.toolbars.bookmarks.visibility" = "always";
-
-      # Theme
-      "extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";
-      "extensions.extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";
-
-      # highlight all entries when searching
-      "findbar.highlightAll" = true;
-
-      # TODO
-      #"extensions.webcompat.enable_picture_in_picture_overrides" = true;
-      #"extensions.webcompat.enable_shims" = true;
-      #"extensions.webcompat.perform_injections" = true;
-      #"extensions.webcompat.perform_ua_overrides" = true;
-
-      # onlykey / copied from a yubikey config
-      #"security.webauth.u2f" = true;
-      #"security.webauth.webauthn" = true;
-      #"security.webauth.webauthn_enable_softtoken" = true;
-      #"security.webauth.webauthn_enable_usbtoken" = true;
-    }
-    (builtins.readFile
-      "${user_js}/user.nix");
+  settings = {
+    # Allow my custom css
+    "toolkit.legacyUserProfileCustomizations.stylesheets" = true;
+
+    # might improve performance TODO
+    "gfx.webrender.all" = true;
+
+    # disable updates (pretty pointless with nix)
+    "extensions.update.autoUpdateDefault" = false;
+    "extensions.update.enabled" = false;
+    "app.update.channel" = "default";
+
+    "browser.ctrlTab.recentlyUsedOrder" = false;
+
+    "browser.download.useDownloadDir" = true;
+    "browser.download.dir" = "${config.home.homeDirectory}/media/downloads";
+    "browser.download.folderList" = 2; # TODO
+    "browser.download.viewableInternally.typeWasRegistered.svg" = true;
+    "browser.download.viewableInternally.typeWasRegistered.webp" = true;
+    "browser.download.viewableInternally.typeWasRegistered.xml" = true;
+
+    # TODO what does this do?
+    "browser.search.widget.inNavBar" = true;
+
+    "browser.shell.checkDefaultBrowser" = false;
+    "browser.tabs.loadInBackground" = true;
+    "browser.urlbar.placeholderName" = "Brave";
+
+    "general.autoScroll" = true;
+
+    # Set the tabs and bookmarks
+    "browser.tabs.inTitlebar" = 1;
+    "browser.toolbars.bookmarks.visibility" = "always";
+
+    # Theme
+    "extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";
+    "extensions.extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";
+
+    # highlight all entries when searching
+    "findbar.highlightAll" = true;
+
+    # TODO
+    #"extensions.webcompat.enable_picture_in_picture_overrides" = true;
+    #"extensions.webcompat.enable_shims" = true;
+    #"extensions.webcompat.perform_injections" = true;
+    #"extensions.webcompat.perform_ua_overrides" = true;
+
+    # onlykey / copied from a yubikey config
+    #"security.webauth.u2f" = true;
+    #"security.webauth.webauthn" = true;
+    #"security.webauth.webauthn_enable_softtoken" = true;
+    #"security.webauth.webauthn_enable_usbtoken" = true;
+  };
 in {
   home.packages = [
     pkgs.firefox-wayland
   ];
-  sessionVariables = {
+  home.sessionVariables = {
     # improve touch input & make scrolling smother
     MOZ_USE_XINPUT2 = "1";
     # improve wayland support
@@ -124,13 +135,13 @@ in {
   programs.firefox = {
     enable = true;
     package = pkgs.firefox;
-    extensions = builtins.map buildFirefoxXpiAddon (lib.attrValues (lib.importJSON ./extensions.json));
-    profile."default" = {
+    profiles."default" = {
+      inherit extensions;
       isDefault = true;
       id = 0;
       name = "default";
 
-      userChrome = builtins.readFile "./chrome/userChrome.css";
+      inherit userChrome;
 
       search = {
         default = "Brave Search";
@@ -215,6 +226,7 @@ in {
         }
       ];
       inherit settings;
+      extraConfig = builtins.readFile "${user_js_nix}/user.js";
     };
   };
 }