From d0a1d841189481c91ccd38cf79c5db834daa4f9f Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 19 Jul 2015 16:20:16 +0200 Subject: Zpkgs tv genid: init --- Zpkgs/tv/default.nix | 1 + Zpkgs/tv/genid.nix | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 Zpkgs/tv/genid.nix diff --git a/Zpkgs/tv/default.nix b/Zpkgs/tv/default.nix index 3ebfdebe..631bb0e8 100644 --- a/Zpkgs/tv/default.nix +++ b/Zpkgs/tv/default.nix @@ -3,6 +3,7 @@ pkgs // { dic = pkgs.callPackage ./dic.nix {}; + genid = pkgs.callPackage ./genid.nix {}; github-hosts-sync = pkgs.callPackage ./github-hosts-sync.nix {}; github-known_hosts = pkgs.callPackage ./github-known_hosts.nix {}; much = pkgs.callPackage ./much.nix {}; diff --git a/Zpkgs/tv/genid.nix b/Zpkgs/tv/genid.nix new file mode 100644 index 00000000..22ef6d29 --- /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 + max=2^32 # see 2^(8*sizeof(uid_t)) + ibase=16 + ($hash + min) % max + " | bc +'' -- cgit v1.2.3