about summary refs log tree commit diff stats
path: root/home-manager/firefox
diff options
context:
space:
mode:
authorene <ene@sils.li>2023-02-11 22:24:30 +0100
committerene <ene@sils.li>2023-02-12 17:48:12 +0100
commit3ad750a3d977b3472a8a67acb7aa3613be7f70bb (patch)
treed3289733fa29b10c835fd8295b5c9737160c10aa /home-manager/firefox
parentFix(home-manager): Import home-manager correctly (diff)
downloadnixos-config-3ad750a3d977b3472a8a67acb7aa3613be7f70bb.tar.gz
nixos-config-3ad750a3d977b3472a8a67acb7aa3613be7f70bb.zip
Fix(home-manager): Improve Firefox configuration
Diffstat (limited to 'home-manager/firefox')
-rw-r--r--home-manager/firefox/default.nix152
-rwxr-xr-xhome-manager/firefox/generate-extension.py41
-rwxr-xr-xhome-manager/firefox/scripts/unzip_mozlz4.py (renamed from home-manager/firefox/unzip_mozlz4.py)0
-rwxr-xr-xhome-manager/firefox/scripts/update_extensions20
-rw-r--r--home-manager/firefox/settings/extensions.json (renamed from home-manager/firefox/extensions.json)33
-rw-r--r--home-manager/firefox/settings/override.js2
6 files changed, 123 insertions, 125 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";
     };
   };
 }
diff --git a/home-manager/firefox/generate-extension.py b/home-manager/firefox/generate-extension.py
deleted file mode 100755
index cfb73542..00000000
--- a/home-manager/firefox/generate-extension.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python
-# source: https://github.com/etu/nixconfig/blob/ba47d577c8bfb4a1c06927c34ece34118f4a0460/modules/graphical/firefox/generate.py
-
-from concurrent.futures import ThreadPoolExecutor
-import json
-import os
-import requests
-
-EXTENSIONS = sorted([
-    "darkreader",
-    "firenvim",
-    "keepassxc-browser",
-    "simple-tab-groups",
-])
-
-def index_ext(ext: str):
-    print(f"Indexing {ext}...")
-
-    resp = requests.get(f"https://addons.mozilla.org/api/v5/addons/addon/{ext}/").json()
-    rel = resp["current_version"]
-
-    if not rel["file"]["hash"].startswith("sha256:"):
-        raise ValueError("Unhandled hash type")
-
-    return {
-        "pname": ext,
-        "version": rel["version"],
-        "addonId": resp["guid"],
-        "url": rel["file"]["url"],
-        "sha256": rel["file"]["hash"],
-    }
-
-if __name__ == "__main__":
-    outfile = os.path.dirname(os.path.realpath(__file__)) + "/extensions.json"
-
-    with ThreadPoolExecutor() as e:
-        extensions = {ext: e.submit(index_ext, ext) for ext in EXTENSIONS}
-        extensions = {k: v.result() for k, v in extensions.items()}
-
-    with open(outfile, "w") as f:
-        json.dump(extensions, f, indent=2)
diff --git a/home-manager/firefox/unzip_mozlz4.py b/home-manager/firefox/scripts/unzip_mozlz4.py
index 311fd214..311fd214 100755
--- a/home-manager/firefox/unzip_mozlz4.py
+++ b/home-manager/firefox/scripts/unzip_mozlz4.py
diff --git a/home-manager/firefox/scripts/update_extensions b/home-manager/firefox/scripts/update_extensions
new file mode 100755
index 00000000..97f7c0ba
--- /dev/null
+++ b/home-manager/firefox/scripts/update_extensions
@@ -0,0 +1,20 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+
+tmp=$(mktmp)
+cat << EOF > $tmp
+    darkreader
+    firenvim
+    keepassxc-browser
+    simple-tab-groups
+    ublock-origin
+EOF
+
+
+nix shell git+https://codeberg.org/ene/generate_moz_extension.git -c generate_extensions $(cat $tmp) > "$(dirname $0)"/../settings/extensions.json
+
+
+
+if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi
diff --git a/home-manager/firefox/extensions.json b/home-manager/firefox/settings/extensions.json
index a7673612..057810bc 100644
--- a/home-manager/firefox/extensions.json
+++ b/home-manager/firefox/settings/extensions.json
@@ -1,30 +1,37 @@
 {
   "darkreader": {
-    "pname": "darkreader",
-    "version": "4.9.62",
     "addonId": "addon@darkreader.org",
+    "pname": "darkreader",
+    "sha256": "sha256:e537a2cee45ed7c26f79ecd3ed362620e3f00d24c158532a58e163a63a3d60cc",
     "url": "https://addons.mozilla.org/firefox/downloads/file/4053589/darkreader-4.9.62.xpi",
-    "sha256": "sha256:e537a2cee45ed7c26f79ecd3ed362620e3f00d24c158532a58e163a63a3d60cc"
+    "version": "4.9.62"
   },
   "firenvim": {
-    "pname": "firenvim",
-    "version": "0.2.14",
     "addonId": "firenvim@lacamb.re",
+    "pname": "firenvim",
+    "sha256": "sha256:a8c495a59e30eaabbb3fcd188db9b5e28b40bffefe41a3f0fa22ecc58c80c2b6",
     "url": "https://addons.mozilla.org/firefox/downloads/file/4026386/firenvim-0.2.14.xpi",
-    "sha256": "sha256:a8c495a59e30eaabbb3fcd188db9b5e28b40bffefe41a3f0fa22ecc58c80c2b6"
+    "version": "0.2.14"
   },
   "keepassxc-browser": {
-    "pname": "keepassxc-browser",
-    "version": "1.8.4",
     "addonId": "keepassxc-browser@keepassxc.org",
+    "pname": "keepassxc-browser",
+    "sha256": "sha256:cc39aa058cb8915cfc88424e2e1cebe3ccfc3f95d7bddb2abd0c4905d2b17719",
     "url": "https://addons.mozilla.org/firefox/downloads/file/4045866/keepassxc_browser-1.8.4.xpi",
-    "sha256": "sha256:cc39aa058cb8915cfc88424e2e1cebe3ccfc3f95d7bddb2abd0c4905d2b17719"
+    "version": "1.8.4"
   },
   "simple-tab-groups": {
-    "pname": "simple-tab-groups",
-    "version": "4.7.2.1",
     "addonId": "simple-tab-groups@drive4ik",
+    "pname": "simple-tab-groups",
+    "sha256": "sha256:75077589098ca62c00b86cf9554c6120bf8dc04c5f916fe26f84915f5147b2a4",
     "url": "https://addons.mozilla.org/firefox/downloads/file/3873608/simple_tab_groups-4.7.2.1.xpi",
-    "sha256": "sha256:75077589098ca62c00b86cf9554c6120bf8dc04c5f916fe26f84915f5147b2a4"
+    "version": "4.7.2.1"
+  },
+  "ublock-origin": {
+    "addonId": "uBlock0@raymondhill.net",
+    "pname": "ublock-origin",
+    "sha256": "sha256:6bf8af5266353fab5eabdc7476de026e01edfb7901b0430c5e539f6791f1edc8",
+    "url": "https://addons.mozilla.org/firefox/downloads/file/4047353/ublock_origin-1.46.0.xpi",
+    "version": "1.46.0"
   }
-}
\ No newline at end of file
+}
diff --git a/home-manager/firefox/settings/override.js b/home-manager/firefox/settings/override.js
index 1f92735b..ca03e8ed 100644
--- a/home-manager/firefox/settings/override.js
+++ b/home-manager/firefox/settings/override.js
@@ -56,7 +56,7 @@ user_pref("browser.safebrowsing.downloads.remote.enabled", true); // 0403
 user_pref("network.prefetch-next", true); // 0601
 
 // enable ipv6 because the rest of the system uses it
-user_pref("network.dns.disableIPv6", true); // 0701
+user_pref("network.dns.disableIPv6", false); // 0701
 
 // TRR only
 user_pref("network.trr.mode", 3); // 0710