2021-02-05 17:12:51 +00:00
|
|
|
{ lib
|
|
|
|
, fetchFromGitHub
|
|
|
|
, python3
|
|
|
|
, writeText
|
|
|
|
, writeShellScript
|
|
|
|
, sqlite
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
2021-02-05 17:12:51 +00:00
|
|
|
pypkgs = python3.pkgs;
|
|
|
|
|
2020-04-24 23:36:52 +00: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-02-05 17:12:51 +00:00
|
|
|
dbScript = writeShellScript "create_pykms_db.sh" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
set -eEuo pipefail
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
db=''${1:-/var/lib/pykms/clients.db}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if [ ! -e $db ] ; then
|
2021-02-05 17:12:51 +00:00
|
|
|
${lib.getBin sqlite}/bin/sqlite3 $db < ${dbSql}
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
2021-02-05 17:12:51 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
in
|
|
|
|
pypkgs.buildPythonApplication rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "pykms";
|
2021-02-05 17:12:51 +00:00
|
|
|
version = "unstable-2021-01-25";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2022-07-14 12:49:19 +00:00
|
|
|
owner = "Py-KMS-Organization";
|
2021-02-05 17:12:51 +00:00
|
|
|
repo = "py-kms";
|
2022-07-14 12:49:19 +00:00
|
|
|
rev = "1435c86fe4f11aa7fd42d77fa61715ca3015eeab";
|
|
|
|
hash = "sha256-9KiMbS0uKTbWSZVIv5ziIeR9c8+EKfKd20yPmjCX7GQ=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
sourceRoot = "${src.name}/py-kms";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
propagatedBuildInputs = with pypkgs; [ systemd pytz tzlocal dnspython ];
|
2020-05-03 17:38:23 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
postPatch = ''
|
|
|
|
siteDir=$out/${python3.sitePackages}
|
|
|
|
|
|
|
|
substituteInPlace pykms_DB2Dict.py \
|
|
|
|
--replace "'KmsDataBase.xml'" "'$siteDir/KmsDataBase.xml'"
|
|
|
|
'';
|
|
|
|
|
|
|
|
format = "other";
|
|
|
|
|
|
|
|
# there are no tests
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $siteDir
|
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
PYTHONPATH="$PYTHONPATH:$siteDir"
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
mv * $siteDir
|
|
|
|
for b in Client Server ; do
|
2021-02-05 17:12:51 +00:00
|
|
|
makeWrapper ${python3.interpreter} $out/bin/''${b,,} \
|
|
|
|
--argv0 pykms-''${b,,} \
|
2022-07-14 12:49:19 +00:00
|
|
|
--add-flags $siteDir/pykms_$b.py \
|
|
|
|
--set PYTHONPATH $PYTHONPATH
|
2020-04-24 23:36:52 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
install -Dm755 ${dbScript} $out/libexec/create_pykms_db.sh
|
|
|
|
|
|
|
|
install -Dm644 ../README.md -t $out/share/doc/pykms
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
${python3.interpreter} -m compileall $siteDir
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Windows KMS (Key Management Service) server written in Python";
|
2022-07-14 12:49:19 +00:00
|
|
|
homepage = "https://github.com/Py-KMS-Organization/py-kms";
|
2021-02-05 17:12:51 +00:00
|
|
|
license = licenses.unlicense;
|
2022-07-14 12:49:19 +00:00
|
|
|
maintainers = with maintainers; [ peterhoeg zopieux ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|