diff options
Diffstat (limited to 'Zpkgs/tv/genid.nix')
-rw-r--r-- | Zpkgs/tv/genid.nix | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Zpkgs/tv/genid.nix b/Zpkgs/tv/genid.nix new file mode 100644 index 000000000..22ef6d29b --- /dev/null +++ b/Zpkgs/tv/genid.nix @@ -0,0 +1,21 @@ +{ lib, pkgs, ... }: + +pkgs.writeScriptBin "genid" '' + #! /bin/sh + # usage: genid NAME + set -euf + + export PATH=${lib.makeSearchPath "bin" (with pkgs; [ + bc + coreutils + ])} + + name=$1 + hash=$(printf %s "$name" | sha1sum | cut -d\ -f1 | tr a-f A-F) + echo " + min=2^16 # bigger than nobody and nogroup, see <nixos/modules/misc/ids.nix> + max=2^32 # see 2^(8*sizeof(uid_t)) + ibase=16 + ($hash + min) % max + " | bc +'' |