summaryrefslogtreecommitdiffstats
path: root/Zpkgs/tv
diff options
context:
space:
mode:
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
+''