From 061314a062b6e14bd03cb73da746741da5f1a9d1 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Tue, 22 Apr 2025 16:23:34 +0200 Subject: [PATCH] programmatically place generated files in development environment this allows to add more generated files later as needed without cluttering the `shellHook`. --- panel/default.nix | 8 ++++++-- panel/nix/package.nix | 14 +++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/panel/default.nix b/panel/default.nix index 767802be..a9c20f84 100644 --- a/panel/default.nix +++ b/panel/default.nix @@ -12,10 +12,11 @@ let manage = pkgs.writeScriptBin "manage" '' exec ${pkgs.lib.getExe pkgs.python3} ${toString ./src/manage.py} $@ ''; + package = pkgs.callPackage ./nix/package.nix { }; in { shell = pkgs.mkShellNoCC { - inputsFrom = [ (pkgs.callPackage ./nix/package.nix { }) ]; + inputsFrom = [ package ]; packages = [ pkgs.npins manage @@ -26,7 +27,10 @@ in DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3"; }; 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. # use this directory for testing with local secrets mkdir -p $CREDENTIALS_DIRECTORY diff --git a/panel/nix/package.nix b/panel/nix/package.nix index 9337887c..267aafe6 100644 --- a/panel/nix/package.nix +++ b/panel/nix/package.nix @@ -25,6 +25,12 @@ let 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; @@ -54,11 +60,17 @@ python3.pkgs.buildPythonPackage { ] ++ 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" - 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 + )} ''; }