about summary refs log tree commit diff stats
path: root/hm/soispha/conf/firefox/config
diff options
context:
space:
mode:
Diffstat (limited to 'hm/soispha/conf/firefox/config')
-rw-r--r--hm/soispha/conf/firefox/config/bookmarks/default.nix46
-rw-r--r--hm/soispha/conf/firefox/config/bookmarks/lib.nix49
-rw-r--r--hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/default.nix28
-rw-r--r--hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/video-pauser.nix46
-rw-r--r--hm/soispha/conf/firefox/config/policies/default.nix141
-rw-r--r--hm/soispha/conf/firefox/config/prefs/default.nix6
6 files changed, 294 insertions, 22 deletions
diff --git a/hm/soispha/conf/firefox/config/bookmarks/default.nix b/hm/soispha/conf/firefox/config/bookmarks/default.nix
index 8315cffd..c612bf4d 100644
--- a/hm/soispha/conf/firefox/config/bookmarks/default.nix
+++ b/hm/soispha/conf/firefox/config/bookmarks/default.nix
@@ -1,21 +1,31 @@
-[
-  {
-    name = "Feed - Piped";
-    url = "https://piped.video/feed";
-  }
+{
+  lib,
+  pkgs,
+  ...
+}: let
+  bookmarks = [
+    {
+      name = "Feed - Piped";
+      url = "https://piped.video/feed";
+    }
 
-  {
-    name = "DeepL Translate";
-    url = "https://www.deepl.com/translator";
-  }
+    {
+      name = "DeepL Translate";
+      url = "https://www.deepl.com/translator";
+    }
 
-  {
-    name = "Nix lib";
-    url = "https://teu5us.github.io/nix-lib.html";
-  }
+    {
+      name = "Nix lib";
+      url = "https://teu5us.github.io/nix-lib.html";
+    }
 
-  {
-    name = "Nixpkgs manual";
-    url = "https://ryantm.github.io/nixpkgs/";
-  }
-]
+    {
+      name = "Nixpkgs manual";
+      url = "https://ryantm.github.io/nixpkgs/";
+    }
+  ];
+
+  mkBookmarksFile = (import ./lib.nix) {inherit lib pkgs;};
+  bookmarks_file = mkBookmarksFile bookmarks;
+in
+  bookmarks_file
diff --git a/hm/soispha/conf/firefox/config/bookmarks/lib.nix b/hm/soispha/conf/firefox/config/bookmarks/lib.nix
new file mode 100644
index 00000000..d1d89dd2
--- /dev/null
+++ b/hm/soispha/conf/firefox/config/bookmarks/lib.nix
@@ -0,0 +1,49 @@
+{
+  lib,
+  pkgs,
+}: bookmarks: let
+  indent = level:
+    lib.concatStringsSep "" (map (lib.const "  ") (lib.range 1 level));
+
+  bookmarkToHTML = indentLevel: bookmark: ''
+    ${indent indentLevel}<DT><A HREF="${
+      lib.escapeXML bookmark.url
+    }" ADD_DATE="0" LAST_MODIFIED="0">${lib.escapeXML bookmark.name}</A>'';
+
+  directoryToHTML = indentLevel: directory: ''
+    ${indent indentLevel}<DT>${
+      if directory.toolbar
+      then ''<H3 PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar''
+      else "<H3>${lib.escapeXML directory.name}"
+    }</H3>
+    ${indent indentLevel}<DL><p>
+    ${allItemsToHTML (indentLevel + 1) directory.bookmarks}
+    ${indent indentLevel}</p></DL>'';
+
+  itemToHTMLOrRecurse = indentLevel: item:
+    if item ? "url"
+    then bookmarkToHTML indentLevel item
+    else directoryToHTML indentLevel item;
+
+  allItemsToHTML = indentLevel: bookmarks:
+    lib.concatStringsSep "\n"
+    (map (itemToHTMLOrRecurse indentLevel) bookmarks);
+
+  bookmarkEntries = allItemsToHTML 1 bookmarks;
+in
+  pkgs.writeText "firefox-bookmarks.html" ''
+    <!DOCTYPE NETSCAPE-Bookmark-file-1>
+    <!-- This is an automatically generated file.
+      It will be read and overwritten.
+      DO NOT EDIT! -->
+    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
+    <TITLE>Bookmarks</TITLE>
+    <H1>Bookmarks Menu</H1>
+
+    <DL><p>
+        <DT><H3 ADD_DATE="0" LAST_MODIFIED="0" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3>
+        <DL><p>
+        ${bookmarkEntries}
+        </DL><p>
+    </p></DL>
+  ''
diff --git a/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/default.nix b/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/default.nix
new file mode 100644
index 00000000..053b6465
--- /dev/null
+++ b/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/default.nix
@@ -0,0 +1,28 @@
+{
+  pkgs,
+  video_pause,
+  ...
+}: let
+  video_pause_ext = import ./video-pauser.nix {inherit pkgs video_pause;};
+in
+  /*
+  ++ lib.optional (cfg.enableBrowserpass or false) (lib.getBin browserpass)
+  ++ lib.optional (cfg.enableBukubrow or false) bukubrow
+  ++ lib.optional (cfg.enableTridactylNative or false) tridactyl-native
+  ++ lib.optional (cfg.enableGnomeExtensions or false) gnome-browser-connector
+  ++ lib.optional (cfg.enableUgetIntegrator or false) uget-integrator
+  ++ lib.optional (cfg.enablePlasmaBrowserIntegration or false) plasma5Packages.plasma-browser-integration
+  ++ lib.optional (cfg.enableFXCastBridge or false) fx-cast-bridge
+  ++ lib.optional (cfg.enableKeePassXC or false) keepassxc
+
+
+  mkdir -p $out/lib/mozilla/native-messaging-hosts
+  for ext in ${toString nativeMessagingHosts}; do
+      ln -sLt $out/lib/mozilla/native-messaging-hosts $ext/lib/mozilla/native-messaging-hosts/*
+  done
+  */
+  with pkgs; [
+    video_pause_ext
+    tridactyl-native
+    keepassxc
+  ]
diff --git a/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/video-pauser.nix b/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/video-pauser.nix
new file mode 100644
index 00000000..a652b596
--- /dev/null
+++ b/hm/soispha/conf/firefox/config/extensions/native_messaging_hosts/video-pauser.nix
@@ -0,0 +1,46 @@
+{
+  pkgs,
+  video_pause,
+  ...
+}: let
+  extensions = builtins.fromJSON (builtins.readFile ../extensions.json);
+  inherit (extensions) video-pauser;
+in
+  /*
+  mkdir -p $out/lib/mozilla/native-messaging-hosts
+  for ext in ${toString nativeMessagingHosts}; do
+      ln -sLt $out/lib/mozilla/native-messaging-hosts $ext/lib/mozilla/native-messaging-hosts/*
+  done
+  */
+  pkgs.stdenv.mkDerivation {
+    inherit (video-pauser) pname version;
+    buildInputs = [
+      video_pause
+    ];
+    buildPhase = ''
+      mkdir -p $out/share/
+      cat << EOF > $out/share/"${video-pauser.pname}".json
+      {
+        "name": "${video-pauser.pname}",
+        "description": "Stop a video with a native hotkey",
+        "path": "${video_pause}/bin/video_pause",
+        "type": "stdio",
+        "allowed_extensions": ["${video-pauser.addonId}"]
+      }
+      EOF
+
+      nativeMessagingPaths="$(cat << EOF
+        lib/mozilla/native-messaging-hosts
+        lib/librewolf/native-messaging-hosts
+        etc/opt/chrome/native-messaging-hosts
+        etc/chromium/native-messaging-hosts
+        etc/vivaldi/native-messaging-hosts
+      EOF
+      )"
+
+      cat "$nativeMessagingPaths" | while read -r path; do
+        mkdir -p $out/$path;
+        cp $out/share/"${video-pauser.pname}".json $out/$path/
+      done
+    '';
+  }
diff --git a/hm/soispha/conf/firefox/config/policies/default.nix b/hm/soispha/conf/firefox/config/policies/default.nix
new file mode 100644
index 00000000..ada281d8
--- /dev/null
+++ b/hm/soispha/conf/firefox/config/policies/default.nix
@@ -0,0 +1,141 @@
+{
+  config,
+  extensions,
+  ...
+}: let
+  locals = [
+    "en-CA"
+    "de"
+    "sv-SE"
+  ];
+in {
+  policies = let
+    mkAllowedExtension = extension: {
+      name = extension.addonId;
+      value = {
+        installation_mode = "normal_installed";
+        updates_disabled = true;
+        inherit (extension) default_area;
+        install_url = "file://${builtins.fetchurl {
+          inherit
+            (extension)
+            url
+            sha256
+            ;
+        }}";
+      };
+    };
+    allowedExtensions =
+      builtins.listToAttrs
+      (builtins.map mkAllowedExtension (builtins.attrValues
+          extensions));
+
+    mkBlockedExtension = id: {
+      name = id;
+      value = {
+        install_mode = "blocked";
+      };
+    };
+    blockedExtensions = builtins.listToAttrs (builtins.map mkBlockedExtension [
+      # these are the default search engines
+      "addons-search-detection@mozilla.com"
+      "amazon@search.mozilla.org"
+      "bing@search.mozilla.org"
+      "ddg@search.mozilla.org"
+      "google@search.mozilla.org"
+      "wikipedia@search.mozilla.org"
+    ]);
+
+    language_packs = builtins.listToAttrs (builtins.map
+      (
+        lang: {
+          name = "langpack-${lang}@firefox.mozilla.org";
+          value = {
+            installation_mode = "normal_installed";
+            install_url = "https://releases.mozilla.org/pub/firefox/releases/${config.soispha.firefox.package_version}/linux-x86_64/xpi/${lang}.xpi";
+          };
+        }
+      )
+      locals);
+  in {
+    # NOTE: See https://mozilla.github.io/policy-templates for documentation <2023-10-21>
+
+    # NixOS manages this already
+    DisableAppUpdate = true;
+
+    DisableFirefoxAccounts = true;
+    DisableFirefoxScreenshots = true;
+
+    # KeepassXC does this for me
+    DisableMasterPasswordCreation = true;
+
+    # I use a self-hosted services for that
+    DisablePocket = true;
+
+    # I don't want to lose my data
+    DisableProfileRefresh = true;
+
+    DisplayBookmarksToolbar = "newtab";
+    DisplayMenuBar = "default-off";
+
+    DNSOverHTTPS = {
+      Enabled = true;
+      Locked = false;
+    };
+    # The concept of a "default browser" does not apply to my NixOS config
+    DontCheckDefaultBrowser = true;
+
+    EnableTrackingProtection = {
+      Value = true;
+      Locked = false;
+      Cryptomining = true;
+      Fingerprinting = true;
+      EmailTracking = true;
+    };
+
+    EncryptedMediaExtensions = {
+      # I want a _free_ config (and I can always just run another browser)
+      Enabled = false;
+      Locked = true;
+    };
+
+    ExtensionSettings =
+      {
+        "*" = {
+          blocked_install_message = ''
+            You can't install a extension manually,
+            please specify it in your NixOS configuration
+          '';
+          installation_mode = "blocked";
+        };
+      }
+      // allowedExtensions
+      // blockedExtensions
+      // language_packs;
+    ExtensionUpdate = false;
+
+    # TODO: Add handlers for the default file types <2023-10-21>
+    # Handlers = {
+    # };
+
+    HardwareAcceleration = true;
+
+    InstallAddonsPermission = {
+      Allowed = [];
+      Default = false;
+    };
+
+    # KeepassXC and such things
+    OfferToSaveLogins = false;
+    PasswordManagerEnable = false;
+
+    PDFjs = {
+      Enabled = true;
+      # Don't honor documents right to be un-copy-able
+      EnablePermissions = false;
+    };
+
+    SearchBar = "unified";
+    RequestedLocales = locals;
+  };
+}
diff --git a/hm/soispha/conf/firefox/config/prefs/default.nix b/hm/soispha/conf/firefox/config/prefs/default.nix
index 6bcaf76f..80c6d274 100644
--- a/hm/soispha/conf/firefox/config/prefs/default.nix
+++ b/hm/soispha/conf/firefox/config/prefs/default.nix
@@ -2,11 +2,9 @@
   pkgs,
   config,
   user_js,
-  lib,
+  bookmarks,
   ...
 }: let
-  bookmarks = import ../bookmarks;
-  firefoxBookmarksFile = (import ../../functions/bookmarks) {inherit lib pkgs;};
   user_js_override = pkgs.writeText "user.override.js" (builtins.readFile ./override.js);
 in
   pkgs.runCommand "user.js" {} ''
@@ -16,7 +14,7 @@ in
 
     cat << EOF >> $out/user.js;
     // My bookmarks
-    user_pref("browser.bookmarks.file", "${toString (firefoxBookmarksFile bookmarks)}");
+    user_pref("browser.bookmarks.file", "${toString bookmarks}");
     user_pref("browser.startup.homepage", "file:///home/dt/home.html"); // 0103 // TODO: add this from a flake
     user_pref("browser.download.dir", "${config.xdg.userDirs.download}");
     EOF