From 4d04e90f0941350957afe7ffe17e99fe27eca2b9 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 2 Apr 2025 18:13:25 +0200 Subject: refactor(modules/legacy/firefox): Move to by-name This also improves the arkanfox-integration and the profile id generation. --- lib/default.nix | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'lib/default.nix') diff --git a/lib/default.nix b/lib/default.nix index 80227cf4..f18e4b33 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -25,6 +25,34 @@ builtins.foldl' (acc: num: acc + num) 0 (lib.lists.imap0 (index: elem: elem * (pow 2 index)) binaryList); + /* + Converts `string` to a (probably) unique numerical id. + + This is achieved by hashing the string and returning the first six hex-digits + converted to a base 10 number. + + # Type + + idFromString :: String -> Int + + # Arguments + + string + : The string to use as seed for the id generation. + + # Examples + + idFromString "3d-printer" + => 10365713 + */ + idFromString = string: let + inputSeed = + builtins.concatStringsSep "" + (lib.lists.take 6 + (lib.strings.stringToCharacters (builtins.hashString "sha256" string))); + in + lib.trivial.fromHexString inputSeed; + /* source: https://github.com/NixOS/nix/issues/10387#issuecomment-2494597690 @@ -65,5 +93,5 @@ then (base * (pow base (power - 1))) else builtins.throw "Negative powers are not supported"; in { - inherit binaryToDecimal pow; + inherit binaryToDecimal idFromString pow; } -- cgit 1.4.1