diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index c56ba69..73178ea 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -1,17 +1,21 @@ from pathlib import Path from os import environ +# All that comes from the environment needs to be defined here +_DEBUG = bool(environ.get('E11SYNC_DEBUG', False)) +_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static') +_GEOIP_PATH = environ.get("GEOIP_PATH") + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ +######################################## +## No more side effects after this place +######################################## -# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l' -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = _DEBUG ALLOWED_HOSTS = [] @@ -19,8 +23,7 @@ INTERNAL_IPS = ["127.0.0.1"] # Application definition -INSTALLED_APPS = [ - 'debug_toolbar', +INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [ 'compressor', 'signup.apps.SignupConfig', @@ -32,9 +35,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', ] -MIDDLEWARE = [ - 'debug_toolbar.middleware.DebugToolbarMiddleware', - +MIDDLEWARE = (['debug_toolbar.middleware.DebugToolbarMiddleware'] if DEBUG else []) + [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -102,7 +103,7 @@ STATICFILES_FINDERS = [ "compressor.finders.CompressorFinder", ] -STATIC_ROOT = '/tmp/e11sync-static' +STATIC_ROOT = _STATIC_ROOT COMPRESS_PRECOMPILERS = ( # TODO: --style=compressed + source maps @@ -126,4 +127,4 @@ LOGGING = { }, } -GEOIP_PATH = environ["GEOIP_PATH"] +GEOIP_PATH = _GEOIP_PATH diff --git a/app/manage.py b/app/manage.py index cbf2c82..b5c8355 100755 --- a/app/manage.py +++ b/app/manage.py @@ -3,7 +3,6 @@ import os import sys - def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'e11sync.settings') diff --git a/flake.nix b/flake.nix index 107ff5a..3927e6e 100644 --- a/flake.nix +++ b/flake.nix @@ -52,9 +52,28 @@ ''; }; in { + packages.e11sync-static = pkgs.stdenv.mkDerivation { + name = "e11sync-static"; + src = self; + nativeBuildInputs = with pkgs; [ + python3Packages.django_5 + python3Packages.django-compressor + dart-sass + python3 + ]; + buildPhase = '' + mkdir -p $out/static + env \ + E11SYNC_STATIC_ROOT=$out/static \ + E11SYNC_DEBUG= \ + ${pkgs.python3}/bin/python3 \ + ${self}/app/manage.py collectstatic + ''; + }; devShells.default = pkgs.mkShellNoCC { LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; GEOIP_PATH = "${geoip}"; + E11SYNC_DEBUG = "1"; packages = devDeps; };