2023-09-07 03:05:27 +02:00
|
|
|
{ lib, stdenv, fetchFromGitHub, fetchYarnDeps, mkYarnPackage, nixosTests, writeText, python3 }:
|
2021-01-18 23:18:23 +01:00
|
|
|
|
|
|
|
let
|
2024-02-28 23:45:41 +01:00
|
|
|
version = "0.4.2";
|
2021-01-18 23:18:23 +01:00
|
|
|
src = fetchFromGitHub {
|
2023-02-10 23:05:45 +01:00
|
|
|
owner = "PowerDNS-Admin";
|
2021-01-18 23:18:23 +01:00
|
|
|
repo = "PowerDNS-Admin";
|
|
|
|
rev = "v${version}";
|
2024-02-28 23:45:41 +01:00
|
|
|
hash = "sha256-q9mt8wjSNFb452Xsg+qhNOWa03KJkYVGAeCWVSzZCyk=";
|
2021-01-18 23:18:23 +01:00
|
|
|
};
|
|
|
|
|
2023-01-28 03:38:15 +01:00
|
|
|
python = python3;
|
2021-06-22 23:35:46 +02:00
|
|
|
|
|
|
|
pythonDeps = with python.pkgs; [
|
2023-08-23 15:53:13 +02:00
|
|
|
flask flask-assets flask-login flask-sqlalchemy flask-migrate flask-seasurf flask-mail flask-session flask-session-captcha flask-sslify
|
2021-12-17 10:33:40 +01:00
|
|
|
mysqlclient psycopg2 sqlalchemy
|
2023-02-10 23:05:45 +01:00
|
|
|
certifi cffi configobj cryptography bcrypt requests python-ldap pyotp qrcode dnspython
|
|
|
|
gunicorn itsdangerous python3-saml pytz rcssmin rjsmin authlib bravado-core
|
|
|
|
lima lxml passlib pyasn1 pytimeparse pyyaml jinja2 itsdangerous webcolors werkzeug zipp zxcvbn
|
2021-01-18 23:18:23 +01:00
|
|
|
];
|
|
|
|
|
2023-12-02 16:39:55 +01:00
|
|
|
all_patches = [
|
|
|
|
./0001-Fix-flask-2.3-issue.patch
|
|
|
|
];
|
2023-10-29 21:20:02 +01:00
|
|
|
|
2021-01-18 23:18:23 +01:00
|
|
|
assets = mkYarnPackage {
|
|
|
|
inherit src version;
|
|
|
|
packageJSON = ./package.json;
|
2023-09-07 03:05:27 +02:00
|
|
|
|
|
|
|
offlineCache = fetchYarnDeps {
|
|
|
|
yarnLock = "${src}/yarn.lock";
|
2024-02-28 23:45:41 +01:00
|
|
|
hash = "sha256-rXIts+dgOuZQGyiSke1NIG7b4lFlR/Gfu3J6T3wP3aY=";
|
2023-09-07 03:05:27 +02:00
|
|
|
};
|
|
|
|
|
2023-02-10 23:05:45 +01:00
|
|
|
# Copied from package.json, see also
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/214952
|
|
|
|
packageResolutions = {
|
|
|
|
"@fortawesome/fontawesome-free" = "6.3.0";
|
|
|
|
};
|
2021-01-18 23:18:23 +01:00
|
|
|
|
|
|
|
nativeBuildInputs = pythonDeps;
|
2023-12-02 16:39:55 +01:00
|
|
|
patches = all_patches ++ [
|
|
|
|
./0002-Remove-cssrewrite-filter.patch
|
|
|
|
];
|
2021-01-18 23:18:23 +01:00
|
|
|
buildPhase = ''
|
|
|
|
# The build process expects the directory to be writable
|
|
|
|
# with node_modules at a specific path
|
2023-02-10 23:05:45 +01:00
|
|
|
# https://github.com/PowerDNS-Admin/PowerDNS-Admin/blob/master/.yarnrc
|
2021-01-18 23:18:23 +01:00
|
|
|
|
|
|
|
approot=deps/powerdns-admin-assets
|
|
|
|
|
|
|
|
ln -s $node_modules $approot/powerdnsadmin/static/node_modules
|
2023-02-10 23:05:45 +01:00
|
|
|
SESSION_TYPE=filesystem FLASK_APP=$approot/powerdnsadmin/__init__.py flask assets build
|
2021-01-18 23:18:23 +01:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
2023-02-10 23:05:45 +01:00
|
|
|
# https://github.com/PowerDNS-Admin/PowerDNS-Admin/blob/54b257768f600c5548a1c7e50eac49c40df49f92/docker/Dockerfile#L43
|
2021-01-18 23:18:23 +01:00
|
|
|
mkdir $out
|
|
|
|
cp -r $approot/powerdnsadmin/static/{generated,assets,img} $out
|
2023-02-10 23:05:45 +01:00
|
|
|
find $node_modules -name webfonts -exec cp -r {} $out \;
|
|
|
|
find $node_modules -name fonts -exec cp -r {} $out \;
|
2021-01-18 23:18:23 +01:00
|
|
|
find $node_modules/icheck/skins/square -name '*.png' -exec cp {} $out/generated \;
|
|
|
|
'';
|
|
|
|
distPhase = "true";
|
|
|
|
};
|
|
|
|
|
|
|
|
assetsPy = writeText "assets.py" ''
|
|
|
|
from flask_assets import Environment
|
|
|
|
assets = Environment()
|
|
|
|
assets.register('js_login', 'generated/login.js')
|
|
|
|
assets.register('js_validation', 'generated/validation.js')
|
|
|
|
assets.register('css_login', 'generated/login.css')
|
|
|
|
assets.register('js_main', 'generated/main.js')
|
|
|
|
assets.register('css_main', 'generated/main.css')
|
|
|
|
'';
|
2023-02-10 23:05:45 +01:00
|
|
|
in stdenv.mkDerivation {
|
2021-01-18 23:18:23 +01:00
|
|
|
pname = "powerdns-admin";
|
|
|
|
|
|
|
|
inherit src version;
|
|
|
|
|
2021-06-22 23:35:46 +02:00
|
|
|
nativeBuildInputs = [ python.pkgs.wrapPython ];
|
2021-01-18 23:18:23 +01:00
|
|
|
|
|
|
|
pythonPath = pythonDeps;
|
|
|
|
|
|
|
|
gunicornScript = ''
|
|
|
|
#!/bin/sh
|
|
|
|
if [ ! -z $CONFIG ]; then
|
|
|
|
exec python -m gunicorn.app.wsgiapp "powerdnsadmin:create_app(config='$CONFIG')" "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec python -m gunicorn.app.wsgiapp "powerdnsadmin:create_app()" "$@"
|
|
|
|
'';
|
|
|
|
|
2023-12-02 16:39:55 +01:00
|
|
|
patches = all_patches ++ [
|
|
|
|
./0003-Fix-flask-migrate-4.0-compatibility.patch
|
|
|
|
./0004-Fix-flask-session-and-powerdns-admin-compatibility.patch
|
|
|
|
./0005-Use-app-context-to-create-routes.patch
|
|
|
|
./0006-Register-modules-before-starting.patch
|
|
|
|
];
|
|
|
|
|
2021-01-18 23:18:23 +01:00
|
|
|
postPatch = ''
|
|
|
|
rm -r powerdnsadmin/static powerdnsadmin/assets.py
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
# Nasty hack: call wrapPythonPrograms to set program_PYTHONPATH (see tribler)
|
|
|
|
wrapPythonPrograms
|
|
|
|
|
|
|
|
mkdir -p $out/share $out/bin
|
2021-12-17 10:33:40 +01:00
|
|
|
cp -r migrations powerdnsadmin $out/share/
|
2021-01-18 23:18:23 +01:00
|
|
|
|
|
|
|
ln -s ${assets} $out/share/powerdnsadmin/static
|
|
|
|
ln -s ${assetsPy} $out/share/powerdnsadmin/assets.py
|
|
|
|
|
|
|
|
echo "$gunicornScript" > $out/bin/powerdns-admin
|
|
|
|
chmod +x $out/bin/powerdns-admin
|
|
|
|
wrapProgram $out/bin/powerdns-admin \
|
2021-06-22 23:35:46 +02:00
|
|
|
--set PATH ${python.pkgs.python}/bin \
|
2021-01-18 23:18:23 +01:00
|
|
|
--set PYTHONPATH $out/share:$program_PYTHONPATH
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2021-12-17 10:33:40 +01:00
|
|
|
passthru = {
|
|
|
|
# PYTHONPATH of all dependencies used by the package
|
|
|
|
pythonPath = python3.pkgs.makePythonPath pythonDeps;
|
|
|
|
tests = nixosTests.powerdns-admin;
|
|
|
|
};
|
|
|
|
|
2021-01-18 23:18:23 +01:00
|
|
|
meta = with lib; {
|
|
|
|
description = "A PowerDNS web interface with advanced features";
|
2024-03-19 03:14:51 +01:00
|
|
|
mainProgram = "powerdns-admin";
|
2023-02-10 23:05:45 +01:00
|
|
|
homepage = "https://github.com/PowerDNS-Admin/PowerDNS-Admin";
|
2021-01-18 23:18:23 +01:00
|
|
|
license = licenses.mit;
|
2021-11-23 22:00:08 +01:00
|
|
|
maintainers = with maintainers; [ Flakebi zhaofengli ];
|
2021-01-18 23:18:23 +01:00
|
|
|
};
|
|
|
|
}
|