programmatically place generated files in development environment

this allows to add more generated files later as needed without
cluttering the `shellHook`.
This commit is contained in:
Valentin Gagarin 2025-04-22 16:23:34 +02:00
parent 78ecd2db6e
commit 061314a062
2 changed files with 19 additions and 3 deletions

View file

@ -12,10 +12,11 @@ let
manage = pkgs.writeScriptBin "manage" '' manage = pkgs.writeScriptBin "manage" ''
exec ${pkgs.lib.getExe pkgs.python3} ${toString ./src/manage.py} $@ exec ${pkgs.lib.getExe pkgs.python3} ${toString ./src/manage.py} $@
''; '';
package = pkgs.callPackage ./nix/package.nix { };
in in
{ {
shell = pkgs.mkShellNoCC { shell = pkgs.mkShellNoCC {
inputsFrom = [ (pkgs.callPackage ./nix/package.nix { }) ]; inputsFrom = [ package ];
packages = [ packages = [
pkgs.npins pkgs.npins
manage manage
@ -26,7 +27,10 @@ in
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3"; DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
}; };
shellHook = '' shellHook = ''
ln -sf ${sources.htmx}/dist/htmx.js src/panel/static/htmx.min.js ${lib.concatStringsSep "\n" (
map (file: "ln -sf ${file.from} ${toString ./src/${file.to}}") package.generated
)}
# in production, secrets are passed via CREDENTIALS_DIRECTORY by systemd. # in production, secrets are passed via CREDENTIALS_DIRECTORY by systemd.
# use this directory for testing with local secrets # use this directory for testing with local secrets
mkdir -p $CREDENTIALS_DIRECTORY mkdir -p $CREDENTIALS_DIRECTORY

View file

@ -25,6 +25,12 @@ let
packages = [ "${name}" ] packages = [ "${name}" ]
include-package-data = true include-package-data = true
''; '';
generated = [
{
from = "${sources.htmx}/dist/htmx.min.js";
to = "./panel/static/htmx.min.js";
}
];
in in
python3.pkgs.buildPythonPackage { python3.pkgs.buildPythonPackage {
pname = name; pname = name;
@ -54,11 +60,17 @@ python3.pkgs.buildPythonPackage {
] ]
++ pythonPackages; ++ pythonPackages;
passthru = {
inherit generated;
};
postInstall = '' postInstall = ''
mkdir -p $out/bin mkdir -p $out/bin
cp -v ${src}/manage.py $out/bin/manage.py cp -v ${src}/manage.py $out/bin/manage.py
chmod +x $out/bin/manage.py chmod +x $out/bin/manage.py
wrapProgram $out/bin/manage.py --prefix PYTHONPATH : "$PYTHONPATH" wrapProgram $out/bin/manage.py --prefix PYTHONPATH : "$PYTHONPATH"
cp ${sources.htmx}/dist/htmx.min.js* $out/${python3.sitePackages}/panel/static/ ${lib.concatStringsSep "\n" (
map (file: "cp ${file.from} $out/${python3.sitePackages}/${file.to}") generated
)}
''; '';
} }