summaryrefslogtreecommitdiff
path: root/modules/home
diff options
context:
space:
mode:
Diffstat (limited to 'modules/home')
-rw-r--r--modules/home/arkenfox/arkenfox-hashes.json32
-rw-r--r--modules/home/arkenfox/default.nix126
-rwxr-xr-xmodules/home/arkenfox/update-hashes.py69
3 files changed, 227 insertions, 0 deletions
diff --git a/modules/home/arkenfox/arkenfox-hashes.json b/modules/home/arkenfox/arkenfox-hashes.json
new file mode 100644
index 0000000..7108d9c
--- /dev/null
+++ b/modules/home/arkenfox/arkenfox-hashes.json
@@ -0,0 +1,32 @@
+{
+ "100.0": "sha256-gitVP21/l26hfR+r7+ST2o7pY8ikr2u92n2uzuLgnKs=",
+ "101.0": "sha256-lGRqHEL9I8VgvSiUjT1DngFCsmEzM8n5J7vIfRj6TZM=",
+ "102.0": "sha256-1M1lf3ah4I5KOPlTIZ52uEha8tuQu1wkgkdzEB4iK/0=",
+ "102.1": "sha256-aOufNe+ShT27pasvj/UqEFaMkgFlkd1q8XcoO+3T6Rg=",
+ "103.0": "sha256-MhlZav86gz8bH1aEWyNFNLnc6T7MBU1d3dGHtG2lEnA=",
+ "104.0": "sha256-NyP/kJlV1Ai7os3gMqukKMdRSQ78GAjPCJkZDZtDdeo=",
+ "105.0": "sha256-XUjX+Tno3EU/3IXR/WCn4M5gVR+sKjCzpKcV31dqzWA=",
+ "106.0": "sha256-WB9w/UoFqp/WyRhe87dNqwbMAXa8lmsK/QCeTzRWmj8=",
+ "107.0": "sha256-TZKoArzALuCNWNBq3un091eR3uRLAi59z/AZ64Xg3BQ=",
+ "108.0": "sha256-YsQbH6bqp2I52meYf0X0DQpwLlDdu5pK9XHMT/9RqOg=",
+ "109.0": "sha256-ebSx6DaXoGKcCoK6UcDnWvdAW6J2X6pJRPD1Pw7UNOw=",
+ "110.0": "sha256-pPJH69y29aV1fc3lrlPl5pMLB5ntem+DcAR3rx3gvDE=",
+ "111.0": "sha256-EutseXvFnDkYq95GWiGrTFqI4fqybvsPQlVV0Wy5tFU=",
+ "112.0": "sha256-k4PF8FWN6U+//UmZX4UxzBWbfAgEwQznLVsaFV/fVKo=",
+ "115.0": "sha256-knJa1zI27NsKGwpps3MMrG9K7HDGCDnoRfm16pNR/yM=",
+ "115.1": "sha256-M523JiwiZR0mwjyjNaojSERFt77Dp75cg0Ifd6wTOdU=",
+ "117.0": "sha256-mvQwK11nhZ9yiP9ONeHrP2by5h1UgFSABWkI25YjlN4=",
+ "118.0": "sha256-/wW55BnbryBleWOvIGPA+QgeL28TN8lSuTwiFXTp9ss=",
+ "119.0": "sha256-MAerYaRbaQBqS8WJ3eaq6uxVqQg8diymPbLCU72nDjM=",
+ "122.0": "sha256-624Giuo1TfeXQGzcGK9ETW86esNFhFZ5a46DCjT6K5I=",
+ "126.0": "sha256-XWtFa/K91FOpfCad6b8hp4X+xP8ke9h5t5/uj87W6+w=",
+ "126.1": "sha256-Ex+eSb7tZ428MMJDIF/nqUOtnzjqEIPNaDXJPm9FvuY=",
+ "128.0": "sha256-XLswsa2u2qsUPsLYRYn6lwis7VwSjAW6BRNdI4brbSM=",
+ "133.0": "sha256-iHj+4UGeB1FVGvOWB9ZZA4aiiJynBxRSFFfJqToYEdQ=",
+ "94.1": "sha256-pMGIfSY7GBew3hM1HYYq1t1/OBHEuqHU+2mZ3OBVL4Y=",
+ "95.0": "sha256-4g1Vu4zF+EtHK123zSxIDP1wYROK2rqS897Kcv2C/cI=",
+ "96.0": "sha256-P2C59t4DnM11I9GDL9xyc2m8Ml0T8gRuom7UtWykWnk=",
+ "97.0": "sha256-Df2D2eBifkZpFklPBbE94AvgAUM/NUAAiuqUzp67Hdo=",
+ "98.0": "sha256-HJu+azYJRMW0C5hhU96pkwZxql7Ijpiz2sw9e/JoqR8=",
+ "99.0": "sha256-ScO19N/EVpmMzdN2kkfjYIJN7c0CQdZJ9qMZReqMpI4="
+} \ No newline at end of file
diff --git a/modules/home/arkenfox/default.nix b/modules/home/arkenfox/default.nix
new file mode 100644
index 0000000..58f2501
--- /dev/null
+++ b/modules/home/arkenfox/default.nix
@@ -0,0 +1,126 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+let
+ # ===
+ ## Pollyfill from mkFirefoxModule
+ ## https://github.com/nix-community/home-manager/blob/70fbbf05a5594b0a72124ab211bff1d502c89e3f/modules/programs/firefox/mkFirefoxModule.nix
+ # ===
+
+ inherit (pkgs.stdenv.hostPlatform) isDarwin;
+
+ cfg = config.programs.firefox;
+
+ profilesPath = if isDarwin then "${cfg.configPath}/Profiles" else cfg.configPath;
+
+ # ===
+ ## Actual module
+ # ===
+
+ arkenfoxVersions = lib.mapAttrs (
+ tag: hash:
+ pkgs.fetchFromGitHub {
+ owner = "arkenfox";
+ repo = "user.js";
+ inherit tag hash;
+ }
+ ) (lib.importJSON ./arkenfox-hashes.json);
+
+ arkenfoxProfiles = lib.filterAttrs (lib.const (profile: profile.arkenfox.enable)) cfg.profiles;
+
+ arkenfoxSubmodule =
+ { config, ... }:
+ {
+ options = {
+ arkenfox = {
+ enable = lib.mkEnableOption "arkenfox";
+
+ version = lib.mkOption {
+ type = lib.types.str;
+ default = lib.versions.majorMinor pkgs.firefox.version;
+ defaultText = lib.literalExpression "lib.versions.majorMinor pkgs.firefox.version";
+ description = ''
+ Version of Arkenfox to apply.
+
+ This should match a tag in https://github.com/arkenfox/user.js.
+ '';
+ };
+
+ source = lib.mkOption {
+ type = lib.types.path;
+ internal = true;
+ };
+ };
+ };
+
+ config = {
+ arkenfox.source = lib.mkDefault arkenfoxVersions.${config.arkenfox.version};
+ };
+ };
+in
+
+{
+ options.programs.firefox.profiles = lib.mkOption {
+ type = lib.types.attrsOf (lib.types.submodule arkenfoxSubmodule);
+ };
+
+ config = {
+ home = {
+ # TODO: Find a better way to do this
+ activation.arkenfoxPrefsCleaner = lib.mkIf (arkenfoxProfiles != [ ]) (
+ lib.hm.dag.entryAfter [ "writeBoundary" "linkGeneration" ] (
+ lib.concatLines (
+ lib.mapAttrsToList (lib.const (
+ profile:
+
+ let
+ prefsCleanerPath = "${config.home.homeDirectory}/${profilesPath}/${profile.path}/prefsCleaner.sh";
+ in
+
+ "run --quiet cp ${
+ profile.arkenfox.source + "/prefsCleaner.sh"
+ } ${prefsCleanerPath} && run --quiet ${prefsCleanerPath}"
+ )) arkenfoxProfiles
+ )
+ )
+ );
+
+ file = lib.mkMerge (
+ lib.mapAttrsToList (lib.const (
+ profile:
+
+ let
+ shouldCreateUserJs =
+ profile.preConfig != ""
+ || profile.settings != { }
+ || profile.extraConfig != ""
+ || profile.bookmarks != [ ]
+ || profile.arkenfox.enable;
+
+ userJsPath = "${profilesPath}/${profile.path}/user.js";
+
+ homeManagerUserJs =
+ pkgs.writeText "home-manager-firefox-profile-${profile.name}-home-manager-userjs"
+ (toString config.home.file.${userJsPath}.text);
+ in
+
+ {
+ ${userJsPath} = lib.mkIf shouldCreateUserJs {
+ source = pkgs.runCommand "home-manager-firefox-profile-${profile.name}-userjs" { } ''
+ echo "// Generated by getchoo's Arkenfox module" > $out
+ echo >> $out
+ cat ${profile.arkenfox.source + "/user.js"} >> $out
+ echo >> $out
+ cat ${homeManagerUserJs} >> $out
+ '';
+ };
+ }
+ )) cfg.profiles
+ );
+ };
+ };
+}
diff --git a/modules/home/arkenfox/update-hashes.py b/modules/home/arkenfox/update-hashes.py
new file mode 100755
index 0000000..3834d7a
--- /dev/null
+++ b/modules/home/arkenfox/update-hashes.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env nix-shell
+#! nix-shell --pure -i python3 -p nix python3 python3Packages.requests
+import json
+import requests
+import subprocess
+from pathlib import Path
+
+GITHUB_API = "https://api.github.com"
+ARKENFOX_REPO = "arkenfox/user.js"
+HASHES_FILE = Path("arkenfox-hashes.json")
+
+
+def get_tags():
+ r = requests.get(
+ f"{GITHUB_API}/repos/{ARKENFOX_REPO}/releases",
+ headers={
+ "Accept": "application/vnd.github+json",
+ "X-GitHub-Api-Version": "2022-11-28",
+ },
+ )
+ r.raise_for_status()
+ releases = r.json()
+ return [release["tag_name"] for release in releases]
+
+
+def get_hash_for_tag(tag: str):
+ print(f"❓️ Calculating hash of Arkenfox v{tag}")
+ process = subprocess.run(
+ [
+ "nix",
+ "--experimental-features",
+ "nix-command flakes",
+ "store",
+ "prefetch-file",
+ "--unpack",
+ "--json",
+ f"https://github.com/{ARKENFOX_REPO}/archive/refs/tags/{tag}.tar.gz",
+ ],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ output = json.loads(process.stdout)
+ return output["hash"]
+
+
+tracked_tags = {}
+if HASHES_FILE.exists():
+ with open(HASHES_FILE, "r") as f:
+ tracked_tags = json.load(f)
+
+upstream_tags = get_tags()
+tags_to_update = [tag for tag in upstream_tags if tag not in tracked_tags.keys()]
+old_tracked = tracked_tags.copy()
+
+update_len = len(tags_to_update)
+if update_len < 1:
+ print("😐️ No updates found")
+ exit()
+
+print(f"🏃 Updating with {update_len} tag(s)")
+for tag in tags_to_update:
+ tracked_tags[tag] = get_hash_for_tag(tag)
+
+if tracked_tags != old_tracked:
+ with open(HASHES_FILE, "w") as f:
+ json.dump(tracked_tags, f, indent=2, sort_keys=True)
+
+print("👍️ Done!")