infra/users/lib.nix

20 lines
474 B
Nix
Raw Normal View History

2019-08-11 19:53:02 +01:00
{ lib }:
let
2020-01-22 12:37:13 +01:00
chrs = lib.listToAttrs (lib.imap (i: v: { name = v; value = i + 96; }) lib.lowerChars);
2019-08-11 19:53:02 +01:00
ord = c: builtins.getAttr c chrs;
2020-01-22 12:37:13 +01:00
in
{
2019-08-11 19:53:02 +01:00
# Make a unique UID from a 4-char identifier
2020-01-22 12:37:13 +01:00
mkUid = id: let
# TODO: Assert length
2019-08-11 19:53:02 +01:00
chars = lib.stringToCharacters id;
n = builtins.map (c: lib.mod (ord c) 10) chars;
s = builtins.concatStringsSep "" (builtins.map (i: builtins.toString i) n);
in
assert lib.length chars == 4;
1000 + lib.toInt s;
}