diff options
author | Soispha <soispha@vhack.eu> | 2023-10-20 10:53:13 +0200 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2023-10-20 10:53:13 +0200 |
commit | 3332094c6f69514e2e9158fff9cd6ffb6ac847c3 (patch) | |
tree | 3be546ac87396c3b057968b0c9876695e94eb75f /hm | |
parent | chore(hm/conf/taskwarrior/projects): Update (diff) | |
download | nixos-config-3332094c6f69514e2e9158fff9cd6ffb6ac847c3.tar.gz nixos-config-3332094c6f69514e2e9158fff9cd6ffb6ac847c3.zip |
feat(hm/conf/taswarrior): Generate a firefox profile per project
Diffstat (limited to '')
-rw-r--r-- | hm/soispha/conf/firefox/default.nix | 59 | ||||
-rw-r--r-- | hm/soispha/conf/taskwarrior/firefox/default.nix | 54 | ||||
-rw-r--r-- | hm/soispha/conf/taskwarrior/firefox/lib.nix | 30 |
3 files changed, 119 insertions, 24 deletions
diff --git a/hm/soispha/conf/firefox/default.nix b/hm/soispha/conf/firefox/default.nix index 90347de9..567c0676 100644 --- a/hm/soispha/conf/firefox/default.nix +++ b/hm/soispha/conf/firefox/default.nix @@ -21,6 +21,27 @@ buildFirefoxXpiAddon = (import ./functions/extensions) {inherit pkgs;}; video-pauser = (import ./functions/extensions/video-pauser.nix) {inherit pkgs video_pause;}; + + taskwarriorProfiles = import ../taskwarrior/firefox { + inherit + extensions + userChrome + extraConfig + bookmarks + search + lib + ; + }; + + search = { + default = "Brave Search"; + force = true; + + inherit engines; + }; + + bookmarks = []; + extraConfig = builtins.readFile "${user_js_nix}/user.js"; in { home.packages = [ pkgs.tridactyl-native @@ -49,30 +70,20 @@ in { enableTridactylNative = true; }; }; - profiles = { - "default" = { - inherit extensions; - isDefault = true; - id = 0; - name = "default"; - - inherit userChrome; - - search = { - default = "Brave Search"; - force = true; - - inherit engines; + profiles = + { + "default" = { + inherit extensions search extraConfig bookmarks userChrome; + isDefault = true; + id = 0; + name = "default"; }; - - bookmarks = []; - extraConfig = builtins.readFile "${user_js_nix}/user.js"; - }; - "clean" = { - isDefault = false; - id = 1; - name = "clean"; - }; - }; + "clean" = { + isDefault = false; + id = 1; + name = "clean"; + }; + } + // taskwarriorProfiles; }; } 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))); +} |