about summary refs log tree commit diff stats
path: root/hm/soispha/conf/taskwarrior
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-10-20 10:53:13 +0200
committerSoispha <soispha@vhack.eu>2023-10-20 10:53:13 +0200
commit3332094c6f69514e2e9158fff9cd6ffb6ac847c3 (patch)
tree3be546ac87396c3b057968b0c9876695e94eb75f /hm/soispha/conf/taskwarrior
parentchore(hm/conf/taskwarrior/projects): Update (diff)
downloadnixos-config-3332094c6f69514e2e9158fff9cd6ffb6ac847c3.zip
feat(hm/conf/taswarrior): Generate a firefox profile per project
Diffstat (limited to 'hm/soispha/conf/taskwarrior')
-rw-r--r--hm/soispha/conf/taskwarrior/firefox/default.nix54
-rw-r--r--hm/soispha/conf/taskwarrior/firefox/lib.nix30
2 files changed, 84 insertions, 0 deletions
diff --git a/hm/soispha/conf/taskwarrior/firefox/default.nix b/hm/soispha/conf/taskwarrior/firefox/default.nix
new file mode 100644
index 00000000..5c6dd314
--- /dev/null
+++ b/hm/soispha/conf/taskwarrior/firefox/default.nix
@@ -0,0 +1,54 @@
+{
+  extensions,
+  userChrome,
+  extraConfig,
+  bookmarks,
+  search,
+  lib,
+  ...
+}: let
+  hexLib = import ./lib.nix {inherit lib;};
+  mkProject = project: subproject:
+    if builtins.isString subproject
+    then {
+      name = "${project.name}.${subproject}";
+      prefix = null;
+    }
+    else let
+      name = builtins.elemAt (builtins.attrNames subproject) 0;
+    in {
+      name = "${project.name}.${name}";
+      subprojects = builtins.elemAt (builtins.attrValues subproject) 0;
+      prefix = null;
+    };
+
+  mkProjectName = project:
+    if builtins.hasAttr "subprojects" project
+    then
+      lib.lists.flatten ([project.name]
+        ++ (builtins.map mkProjectName
+          (builtins.map (mkProject project) project.subprojects)))
+    else [project.name];
+  projects = lib.lists.flatten (builtins.map mkProjectName (import ../projects {}));
+
+  mkFirefoxProfile = {
+    name,
+    id,
+  }: {
+    inherit name;
+    value = {
+      isDefault = false;
+      inherit name id extensions userChrome search bookmarks extraConfig;
+    };
+  };
+  projects_id =
+    builtins.map (project: {
+      name = project;
+      id =
+        hexLib.fromHexString
+        (builtins.hashString "sha256" project);
+    })
+    projects;
+  firefoxProfiles = builtins.listToAttrs (builtins.map mkFirefoxProfile projects_id);
+in
+  firefoxProfiles
diff --git a/hm/soispha/conf/taskwarrior/firefox/lib.nix b/hm/soispha/conf/taskwarrior/firefox/lib.nix
new file mode 100644
index 00000000..467b9a73
--- /dev/null
+++ b/hm/soispha/conf/taskwarrior/firefox/lib.nix
@@ -0,0 +1,30 @@
+{lib, ...}: {
+  fromHexString = hexString: let
+    fromHexChar = index: char:
+      {
+        "0" = 0;
+        "1" = 1;
+        "2" = 2;
+        "3" = 3;
+        "4" = 4;
+        "5" = 5;
+        "6" = 6;
+        "7" = 7;
+        "8" = 8;
+        "9" = 9;
+        "A" = 10;
+        "B" = 11;
+        "C" = 12;
+        "D" = 13;
+        "E" = 14;
+        "F" = 15;
+      }
+      .${lib.strings.toUpper char}
+      * (
+        if index == 0
+        then 1
+        else index * 16
+      );
+  in
+    lib.lists.foldr (a: b: a + b) 0 (lib.lists.imap0 fromHexChar (lib.lists.reverseList (lib.strings.stringToCharacters hexString)));
+}