nixpkgs-suyu/pkgs/tools/networking/pykms/default.nix

90 lines
1.9 KiB
Nix
Raw Normal View History

2021-01-31 13:40:19 +01:00
{ lib
, fetchFromGitHub
, python3
, writeText
, writeShellScript
, sqlite
}:
2017-07-25 09:04:28 +02:00
let
2021-01-31 13:40:19 +01:00
pypkgs = python3.pkgs;
2017-07-25 09:04:28 +02:00
dbSql = writeText "create_pykms_db.sql" ''
CREATE TABLE clients(
clientMachineId TEXT,
machineName TEXT,
applicationId TEXT,
skuId TEXT,
licenseStatus TEXT,
lastRequestTime INTEGER,
kmsEpid TEXT,
requestCount INTEGER
);
'';
2021-01-31 13:40:19 +01:00
dbScript = writeShellScript "create_pykms_db.sh" ''
set -eEuo pipefail
2017-07-25 09:04:28 +02:00
2021-01-31 13:40:19 +01:00
db=''${1:-/var/lib/pykms/clients.db}
2017-07-25 09:04:28 +02:00
if [ ! -e $db ] ; then
2021-01-31 13:40:19 +01:00
${lib.getBin sqlite}/bin/sqlite3 $db < ${dbSql}
2017-07-25 09:04:28 +02:00
fi
2021-01-31 13:40:19 +01:00
'';
2017-07-25 09:04:28 +02:00
2021-01-31 13:40:19 +01:00
in
pypkgs.buildPythonApplication rec {
pname = "pykms";
2021-01-31 13:40:19 +01:00
version = "unstable-2021-01-25";
2017-07-25 09:04:28 +02:00
src = fetchFromGitHub {
2021-01-31 13:40:19 +01:00
owner = "SystemRage";
repo = "py-kms";
rev = "a3b0c85b5b90f63b33dfa5ae6085fcd52c6da2ff";
sha256 = "sha256-u0R0uJMQxHnJUDenxglhQkZza3/1DcyXCILcZVceygA=";
2017-07-25 09:04:28 +02:00
};
sourceRoot = "source/py-kms";
2017-07-25 09:04:28 +02:00
2021-01-31 13:40:19 +01:00
propagatedBuildInputs = with pypkgs; [ systemd pytz tzlocal ];
postPatch = ''
siteDir=$out/${python3.sitePackages}
substituteInPlace pykms_DB2Dict.py \
2017-07-25 09:04:28 +02:00
--replace "'KmsDataBase.xml'" "'$siteDir/KmsDataBase.xml'"
'';
format = "other";
2017-07-25 09:04:28 +02:00
# there are no tests
doCheck = false;
installPhase = ''
runHook preInstall
mkdir -p $siteDir
2017-07-25 09:04:28 +02:00
mv * $siteDir
for b in Client Server ; do
2021-01-31 13:40:19 +01:00
makeWrapper ${python3.interpreter} $out/bin/''${b,,} \
--argv0 pykms-''${b,,} \
--add-flags $siteDir/pykms_$b.py
2017-07-25 09:04:28 +02:00
done
install -Dm755 ${dbScript} $out/libexec/create_pykms_db.sh
2017-07-25 09:04:28 +02:00
install -Dm644 ../README.md -t $out/share/doc/pykms
2017-07-25 09:04:28 +02:00
2021-01-31 13:40:19 +01:00
${python3.interpreter} -m compileall $siteDir
2017-07-25 09:04:28 +02:00
runHook postInstall
'';
meta = with lib; {
2017-07-25 09:04:28 +02:00
description = "Windows KMS (Key Management Service) server written in Python";
2021-01-31 13:40:19 +01:00
homepage = "https://github.com/SystemRage/py-kms";
license = licenses.unlicense;
2017-07-25 09:04:28 +02:00
maintainers = with maintainers; [ peterhoeg ];
};
}