1 { lib, stdenv, fetchFromGitHub, fetchYarnDeps, yarnConfigHook, nixosTests, writeText, python3 }:
4 pname = "powerdns-admin";
6 src = fetchFromGitHub {
7 owner = "PowerDNS-Admin";
8 repo = "PowerDNS-Admin";
10 hash = "sha256-q9mt8wjSNFb452Xsg+qhNOWa03KJkYVGAeCWVSzZCyk=";
15 pythonDeps = with python.pkgs; [
17 flask flask-assets flask-login flask-sqlalchemy flask-migrate flask-seasurf flask-mail flask-session flask-session-captcha flask-sslify
18 mysqlclient psycopg2 sqlalchemy
19 certifi cffi configobj cryptography bcrypt requests python-ldap pyotp qrcode dnspython
20 gunicorn itsdangerous python3-saml pytz rcssmin rjsmin authlib bravado-core
21 lima lxml passlib pyasn1 pytimeparse pyyaml jinja2 itsdangerous webcolors werkzeug zipp zxcvbn
25 ./0001-Fix-flask-2.3-issue.patch
28 assets = stdenv.mkDerivation {
29 pname = "${pname}-assets";
32 offlineCache = fetchYarnDeps {
33 yarnLock = "${src}/yarn.lock";
34 hash = "sha256-rXIts+dgOuZQGyiSke1NIG7b4lFlR/Gfu3J6T3wP3aY=";
40 patches = all_patches ++ [
41 ./0002-Remove-cssrewrite-filter.patch
44 SESSION_TYPE=filesystem FLASK_APP=./powerdnsadmin/__init__.py flask assets build
47 # https://github.com/PowerDNS-Admin/PowerDNS-Admin/blob/54b257768f600c5548a1c7e50eac49c40df49f92/docker/Dockerfile#L43
49 cp -r powerdnsadmin/static/{generated,assets,img} $out
50 find powerdnsadmin/static/node_modules -name webfonts -exec cp -r {} $out \; -printf "Copying %P\n"
51 find powerdnsadmin/static/node_modules -name fonts -exec cp -r {} $out \; -printf "Copying %P\n"
52 find powerdnsadmin/static/node_modules/icheck/skins/square -name '*.png' -exec cp {} $out/generated \;
56 assetsPy = writeText "assets.py" ''
57 from flask_assets import Environment
58 assets = Environment()
59 assets.register('js_login', 'generated/login.js')
60 assets.register('js_validation', 'generated/validation.js')
61 assets.register('css_login', 'generated/login.css')
62 assets.register('js_main', 'generated/main.js')
63 assets.register('css_main', 'generated/main.css')
65 in stdenv.mkDerivation {
66 inherit pname version src;
68 nativeBuildInputs = [ python.pkgs.wrapPython ];
70 pythonPath = pythonDeps;
74 if [ ! -z $CONFIG ]; then
75 exec python -m gunicorn.app.wsgiapp "powerdnsadmin:create_app(config='$CONFIG')" "$@"
78 exec python -m gunicorn.app.wsgiapp "powerdnsadmin:create_app()" "$@"
81 patches = all_patches ++ [
82 ./0003-Fix-flask-migrate-4.0-compatibility.patch
83 ./0004-Fix-flask-session-and-powerdns-admin-compatibility.patch
84 ./0005-Use-app-context-to-create-routes.patch
85 ./0006-Register-modules-before-starting.patch
89 rm -r powerdnsadmin/static powerdnsadmin/assets.py
95 # Nasty hack: call wrapPythonPrograms to set program_PYTHONPATH (see tribler)
98 mkdir -p $out/share $out/bin
99 cp -r migrations powerdnsadmin $out/share/
101 ln -s ${assets} $out/share/powerdnsadmin/static
102 ln -s ${assetsPy} $out/share/powerdnsadmin/assets.py
104 echo "$gunicornScript" > $out/bin/powerdns-admin
105 chmod +x $out/bin/powerdns-admin
106 wrapProgram $out/bin/powerdns-admin \
107 --set PATH ${python.pkgs.python}/bin \
108 --set PYTHONPATH $out/share:$program_PYTHONPATH
114 # PYTHONPATH of all dependencies used by the package
115 pythonPath = python3.pkgs.makePythonPath pythonDeps;
116 tests = nixosTests.powerdns-admin;
120 description = "PowerDNS web interface with advanced features";
121 mainProgram = "powerdns-admin";
122 homepage = "https://github.com/PowerDNS-Admin/PowerDNS-Admin";
123 license = licenses.mit;
124 maintainers = with maintainers; [ Flakebi zhaofengli ];