aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-02 18:13:25 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-02 18:15:48 +0200
commit4d04e90f0941350957afe7ffe17e99fe27eca2b9 (patch)
tree93291063f47d4d7f69c7955903141bdacc4b5373 /lib
parentrefactor(treewide): Remove `river_init_lesser` (diff)
downloadnixos-config-4d04e90f0941350957afe7ffe17e99fe27eca2b9.zip
refactor(modules/legacy/firefox): Move to by-name
This also improves the arkanfox-integration and the profile id generation.
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 80227cf4..f18e4b33 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -26,6 +26,34 @@
(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
Raises the `base` to the power of `power`.
@@ -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;
}