lib.uuidFrom: generate a deterministic UUID

This commit is contained in:
Ehmry - 2021-04-02 11:15:15 +02:00
parent 192e9f1b7b
commit d18c6122be
1 changed files with 13 additions and 0 deletions

View File

@ -124,6 +124,19 @@
"abort generators.toDhall: unhandled value (${x})";
};
uuidFrom = seed:
let digest = builtins.hashString "sha256" seed;
in (lib.lists.foldl ({ str, off }:
n:
let chunk = builtins.substring off n digest;
in {
str = if off == 0 then chunk else "${str}-${chunk}";
off = off + n;
}) {
str = "";
off = 0;
} [ 8 4 4 4 12 ]).str;
nixosSystem =
# A derivative of the function for generating Linux NixOS systems.
# This one is not so well tested…