diff --git a/flake.lock b/flake.lock index d9c9cad..7560644 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,44 @@ "type": "github" } }, + "firefox-addons": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "dir": "pkgs/firefox-addons", + "lastModified": 1705103913, + "narHash": "sha256-PX6zS6uni5IXZMUQB2DUbhj+oV7QyAfwEEenOb/DstU=", + "owner": "rycee", + "repo": "nur-expressions", + "rev": "c8e94a42015531a061a4518aff7aee03d5a4f215", + "type": "gitlab" + }, + "original": { + "dir": "pkgs/firefox-addons", + "owner": "rycee", + "repo": "nur-expressions", + "type": "gitlab" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1629284811, + "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c5d161cc0af116a2e17f54316f0bf43f0819785c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flatpaks": { "locked": { "lastModified": 1704403850, @@ -139,6 +177,7 @@ }, "root": { "inputs": { + "firefox-addons": "firefox-addons", "flatpaks": "flatpaks", "home-manager": "home-manager", "nix-colors": "nix-colors", diff --git a/flake.nix b/flake.nix index d10c97f..04171e0 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,11 @@ # Used for theming the OS, see modules/home-manager/theme.nix nix-colors.url = "github:misterio77/nix-colors"; + firefox-addons = { + url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Necessary for modules/home-manager/programs/tmux.nix tmux-plugin-manager = { url = "github:tmux-plugins/tpm"; diff --git a/hosts/desktop/default/home.nix b/hosts/desktop/default/home.nix index 59b3492..a91aa14 100644 --- a/hosts/desktop/default/home.nix +++ b/hosts/desktop/default/home.nix @@ -4,4 +4,5 @@ imports = [ ../shared-home.nix ]; + librewolf.profiles.guz.isDefault = true; } diff --git a/hosts/desktop/shared-home.nix b/hosts/desktop/shared-home.nix index 456496a..b85456e 100644 --- a/hosts/desktop/shared-home.nix +++ b/hosts/desktop/shared-home.nix @@ -4,6 +4,7 @@ imports = [ ../../modules/home-manager/theme.nix ../../modules/home-manager/config/terminal.nix + ../../modules/home-manager/programs/librewolf ./wm.nix ./keybinds.nix ]; @@ -15,9 +16,32 @@ ''; }; + librewolf = { + enable = true; + profiles = { + guz = { + id = 0; + settings = { + "webgl.disabled" = false; + "browser.startup.homepage" = "https://search.brave.com"; + "privacy.clearOnShutdown.history" = false; + "privacy.clearOnShutdown.downloads" = false; + "extensions.activeThemeID" = "firefox-compact-dark@mozilla.org"; + "privacy.clearOnShutdown.cookies" = false; + }; + extensions = with inputs.firefox-addons.packages."x86_64-linux"; [ + darkreader + canvasblocker + smart-referer + ]; + }; + }; + }; + services.flatpak.packages = [ "nz.mega.MEGAsync" "md.obsidian.Obsidian" + "dev.vencord.Vesktop" ]; # services.flatpak.overrides = { }; @@ -25,7 +49,7 @@ nixpkgs.config.allowUnfreePredicate = _: true; home.packages = with pkgs; [ ## Programs - firefox + # firefox # (pkgs.writeShellScriptBin "my-hello" '' # echo "Hello, ${config.home.username}!" diff --git a/hosts/desktop/work/home.nix b/hosts/desktop/work/home.nix index f96f3cf..7e01a6d 100644 --- a/hosts/desktop/work/home.nix +++ b/hosts/desktop/work/home.nix @@ -7,4 +7,23 @@ theme.accent = "94e2d5"; wm.wallpaper = ../../../static/guz-wallpaper-work.webp; + librewolf.profiles.work = { + isDefault = true; + id = 1; + settings = { + "webgl.disabled" = false; + "browser.startup.homepage" = "https://github.com"; + "privacy.clearOnShutdown.history" = false; + "privacy.clearOnShutdown.downloads" = false; + "extensions.activeThemeID" = "firefox-compact-dark@mozilla.org"; + "privacy.clearOnShutdown.cookies" = false; + }; + extensions = with inputs.firefox-addons.packages."x86_64-linux"; [ + darkreader + canvasblocker + smart-referer + github-file-icons + ]; + }; + } diff --git a/modules/home-manager/programs/librewolf/default.nix b/modules/home-manager/programs/librewolf/default.nix new file mode 100644 index 0000000..721068f --- /dev/null +++ b/modules/home-manager/programs/librewolf/default.nix @@ -0,0 +1,415 @@ +/* + THIS FILE ISN'T LICENSED UNDER THE WTFPL LICENSE. + + This file is copied from Home-manager's GitHub and was modified to suit my + (Gustavo "Guz" L. de Mello) personal needs. The original file can be found + here: https://github.com/nix-community/home-manager/blob/master/modules/programs/firefox.nix + + Said file is licensed under the MIT License, which a copy is written below: + + MIT License + + Copyright (c) 2017-2023 Home Manager contributors + Copyright (c) 2023-present Gustavo "Guz" L. de Mello + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +{ inputs, config, lib, pkgs, ... }: + +with lib; +let + cfg = config.librewolf; + + jsonFormat = pkgs.formats.json { }; + + firefoxConfigPath = ".librewolf"; + profilesPath = firefoxConfigPath; + + # The extensions path shared by all profiles; will not be supported + # by future Firefox versions. + extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; + + profiles = flip mapAttrs' cfg.profiles + (_: profile: + nameValuePair "Profile${toString profile.id}" { + Name = profile.name; + Path = profile.path; + IsRelative = 1; + Default = if profile.isDefault then 1 else 0; + }) // { + General = { StartWithLastProfile = 1; }; + }; + + profilesIni = generators.toINI { } profiles; + + userPrefValue = pref: + builtins.toJSON (if isBool pref || isInt pref || isString pref then + pref + else + builtins.toJSON pref); + + mkUserJs = prefs: extraPrefs: bookmarks: + let + prefs' = lib.optionalAttrs ([ ] != bookmarks) + { + "browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks); + "browser.places.importBookmarksHTML" = true; + } // prefs; + in + '' + // Generated by Home Manager. + + ${concatStrings (mapAttrsToList (name: value: '' + user_pref("${name}", ${userPrefValue value}); + '') prefs')} + + ${extraPrefs} + ''; + + mkContainersJson = containers: + let + containerToIdentity = _: container: { + userContextId = container.id; + name = container.name; + icon = container.icon; + color = container.color; + public = true; + }; + in + '' + ${builtins.toJSON { + version = 4; + lastUserContextId = + elemAt (mapAttrsToList (_: container: container.id) containers) 0; + identities = mapAttrsToList containerToIdentity containers; + }} + ''; + + firefoxBookmarksFile = bookmarks: + let + indent = level: + lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level)); + + bookmarkToHTML = indentLevel: bookmark: + '' + ${indent indentLevel}
+ ${allItemsToHTML (indentLevel + 1) directory.bookmarks} + ${indent indentLevel}
''; + + 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" '' + + + +
+ ${bookmarkEntries} +