]> Git — Sourcephile - sourcephile-nix.git/blob - members/lib.nix
gitolite: add on losurdo
[sourcephile-nix.git] / members / lib.nix
1 { lib }:
2 let
3 chrs = lib.listToAttrs (lib.imap (i: v: { name = v; value = i + 96; }) lib.lowerChars);
4 ord = c: builtins.getAttr c chrs;
5 in
6 {
7 # Make a unique UID from a 4-char identifier
8 mkUid = id:
9 let
10 chars = lib.stringToCharacters (builtins.substring 0 4 id);
11 n = builtins.map (c: lib.mod (ord c) 10) chars;
12 s = builtins.concatStringsSep "" (builtins.map (i: builtins.toString i) n);
13 in
14 assert builtins.stringLength id >= 4;
15 assert builtins.length chars == 4;
16 1000 + lib.toInt s;
17 }