users/lib.nix: allow to pass the full user
This commit is contained in:
parent
bc38d42934
commit
202f7fe8f9
1 changed files with 9 additions and 11 deletions
|
@ -1,19 +1,17 @@
|
||||||
{ lib }:
|
{ lib }:
|
||||||
|
|
||||||
let
|
let
|
||||||
chrs = lib.listToAttrs (lib.imap (i: v: { name = v; value = i + 96; }) lib.lowerChars);
|
chrs = lib.listToAttrs (lib.imap (i: v: { name = v; value = i + 96; }) lib.lowerChars);
|
||||||
ord = c: builtins.getAttr c chrs;
|
ord = c: builtins.getAttr c chrs;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Make a unique UID from a 4-char identifier
|
# Make a unique UID from a 4-char identifier
|
||||||
mkUid = id: let
|
mkUid = id:
|
||||||
# TODO: Assert length
|
let
|
||||||
chars = lib.stringToCharacters id;
|
chars = lib.stringToCharacters (builtins.substring 0 4 id);
|
||||||
n = builtins.map (c: lib.mod (ord c) 10) chars;
|
n = builtins.map (c: lib.mod (ord c) 10) chars;
|
||||||
s = builtins.concatStringsSep "" (builtins.map (i: builtins.toString i) n);
|
s = builtins.concatStringsSep "" (builtins.map (i: builtins.toString i) n);
|
||||||
|
in
|
||||||
in
|
assert builtins.stringLength id >= 4;
|
||||||
assert lib.length chars == 4;
|
assert builtins.length chars == 4;
|
||||||
1000 + lib.toInt s;
|
1000 + lib.toInt s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue