mirror of
https://github.com/Gaelan/minifedi
synced 2024-11-10 06:14:17 +00:00
37 lines
867 B
Nix
37 lines
867 B
Nix
{ pkgs }:
|
|
|
|
rec {
|
|
portFromString = string:
|
|
let
|
|
hash = builtins.hashString "sha256" string;
|
|
portHex = builtins.substring 0 4 hash;
|
|
portHexChars = pkgs.lib.strings.stringToCharacters portHex;
|
|
hexDigitToNum = n:
|
|
let
|
|
map = {
|
|
"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;
|
|
};
|
|
in map.${n};
|
|
portFromHash =
|
|
pkgs.lib.lists.foldl (prev: n: (hexDigitToNum n) + (prev * 16)) 0
|
|
portHexChars;
|
|
in if portFromHash <= 1024 then
|
|
portFromString "retry_${string}"
|
|
else
|
|
portFromHash;
|
|
}
|