summaryrefslogtreecommitdiffstats
path: root/Zpkgs/tv
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-07-19 16:20:16 +0200
committertv <tv@shackspace.de>2015-07-19 16:20:16 +0200
commitd0a1d841189481c91ccd38cf79c5db834daa4f9f (patch)
treea8ca98b617848e5a9e55f1b476e4fd0ba511d8f9 /Zpkgs/tv
parent2457f4183b3266b8ca35f9d3036f4fc45e62c407 (diff)
Zpkgs tv genid: init
Diffstat (limited to 'Zpkgs/tv')
-rw-r--r--Zpkgs/tv/default.nix1
-rw-r--r--Zpkgs/tv/genid.nix21
2 files changed, 22 insertions, 0 deletions
diff --git a/Zpkgs/tv/default.nix b/Zpkgs/tv/default.nix
index 3ebfdebe8..631bb0e8d 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 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
+''