diff --git a/modules/nixos/django-apps/default.nix b/modules/nixos/django-apps/default.nix index 14c2b30..d7922e6 100644 --- a/modules/nixos/django-apps/default.nix +++ b/modules/nixos/django-apps/default.nix @@ -445,6 +445,15 @@ in doBackups = mkEnableOption "backups for this site" // { default = true; }; + + extraInit = mkOption { + type = lines; + description = '' + Steps taken during the initialization after the migration is done + and the static files have been collected. + ''; + default = ''''; + }; }; } ) @@ -722,18 +731,24 @@ in inherit after environment path; preStart = '' + # Create the necessary directory with the correct user/group + mkdir -p ${config.mediaDirectory} ${config.staticDirectory} + if [ ! -f .initialized ]; then # The previous initialization might have failed, so restart from the beginning rm -rf source # We need to download the application source and run the migrations first ${lib.getExe pkgs.git} clone --single-branch --branch ${config.branch} ${config.source} source - (cd source && python ${config.managePath} migrate --no-input && python ${config.managePath} collectstatic --no-input) + pushd source + python ${config.managePath} migrate --no-input + python ${config.managePath} collectstatic --no-input + + ${config.extraInit} + + popd touch .initialized fi - - # Create the necessary directory with the correct user/group - mkdir -p ${config.mediaDirectory} ${config.staticDirectory} ''; requires = optional (config.application.type != "daphne") "dj-${name}.socket";