Fediversity/panel/nix/package.nix
Valentin Gagarin 061314a062 programmatically place generated files in development environment
this allows to add more generated files later as needed without
cluttering the `shellHook`.
2025-04-22 16:24:12 +02:00

76 lines
1.6 KiB
Nix

{
lib,
sqlite,
python3,
sources ? import ../../npins,
}:
let
src =
with lib.fileset;
toSource {
root = ../src;
fileset = intersection (gitTracked ../../.) ../src;
};
pyproject = with lib; fromTOML pyproject-toml;
# TODO: define this globally
name = "panel";
# TODO: we may want this in a file so it's easier to read statically
version = "0.0.0";
pyproject-toml = ''
[project]
name = "Fediversity-Panel"
version = "${version}"
[tool.setuptools]
packages = [ "${name}" ]
include-package-data = true
'';
generated = [
{
from = "${sources.htmx}/dist/htmx.min.js";
to = "./panel/static/htmx.min.js";
}
];
in
python3.pkgs.buildPythonPackage {
pname = name;
inherit (pyproject.project) version;
pyproject = true;
inherit src;
preBuild = ''
echo "recursive-include ${name} *" > MANIFEST.in
cp ${builtins.toFile "source" pyproject-toml} pyproject.toml
'';
propagatedBuildInputs =
let
pythonPackages = with python3.pkgs; [
dj-database-url
django-compressor
django-debug-toolbar
django-libsass
django-pydantic-field
django_4
setuptools
];
in
[
sqlite
]
++ pythonPackages;
passthru = {
inherit generated;
};
postInstall = ''
mkdir -p $out/bin
cp -v ${src}/manage.py $out/bin/manage.py
chmod +x $out/bin/manage.py
wrapProgram $out/bin/manage.py --prefix PYTHONPATH : "$PYTHONPATH"
${lib.concatStringsSep "\n" (
map (file: "cp ${file.from} $out/${python3.sitePackages}/${file.to}") generated
)}
'';
}