{"id":13682169,"url":"https://github.com/DavHau/django-nixos","last_synced_at":"2025-04-30T07:30:47.307Z","repository":{"id":52853386,"uuid":"245798015","full_name":"DavHau/django-nixos","owner":"DavHau","description":"NixOS/NixOps configuration for Django","archived":false,"fork":false,"pushed_at":"2021-05-03T12:16:19.000Z","size":29,"stargazers_count":34,"open_issues_count":6,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-10T16:29:33.297Z","etag":null,"topics":["deployment","django","nix","nixops","nixos"],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DavHau.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-08T10:58:35.000Z","updated_at":"2024-09-15T17:52:24.000Z","dependencies_parsed_at":"2022-08-23T10:00:30.583Z","dependency_job_id":null,"html_url":"https://github.com/DavHau/django-nixos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavHau%2Fdjango-nixos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavHau%2Fdjango-nixos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavHau%2Fdjango-nixos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavHau%2Fdjango-nixos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavHau","download_url":"https://codeload.github.com/DavHau/django-nixos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224201897,"owners_count":17272661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","django","nix","nixops","nixos"],"created_at":"2024-08-02T13:01:41.754Z","updated_at":"2024-11-12T01:31:16.837Z","avatar_url":"https://github.com/DavHau.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# NixOS-based Django deployment\n!! WARNING !! This project has not been updated for a while. You can still use this as a template, but make sure to update the nixpkgs version in `nixpkgs-src.nix`\n\nThis Project aims to provide a production grade NixOS configuration for Django projects. By taking your source code and some parameters as input it will return a nixos configuration which serves your Django project.\n\nAn exemplary django project with some example NixOS/NixOps configs can be found under `./examples`\n\n## What you will get\n - A PostgreSQL DB with access configured for django\n - A systemd service which serves the project via gunicorn\n - A defined way of passing secrets to Django without leaking them into /nix/store\n - Your static files as a separated build artifact (by default served via whitenoise)\n - Ability to configure some common options like (allowed-hosts, port, processes, threads) through your nix config.\n - Having your `manage.py` globally callable via `manage-projectname` (only via root/sudo)\n\n\n## Parameters\n```nix\n{ # MANDATORY\n  name,  # create a name for the project\n  keys-file,  # path to a file containing secrets\n  src,  # derivation of django source code\n\n  # OPTIONAL\n  settings, # django settings module like `myproject.settings`\n  pkgs ? import ./nixpkgs-src.nix { config = {}; },  # nixpkgs\n  python ? import ./python.nix { inherit pkgs; },  # python + modules\n  manage-py ? \"${src}/manage.py\",  # path to manage.py inside src\n  static-files ? (import ./static-files.nix { # derivation of static files\n    inherit pkgs python src settings name manage-py;\n  }),\n  wsgi ? \"${name}.wsgi\",  # django wsgi module like `myproject.wsgi`\n  processes ? 5,  # number of proccesses for gunicorn server\n  threads ? 5,  # number of threads for gunicorn server\n  db-name ? name,  # database name\n  user ? \"django\",  # system user for django\n  port ? 80,  # port to bind the http server\n  allowed-hosts ? \"*\",  # string of comma separated hosts\n  ...\n}:\n```\n\n\n\n## Prerequisites\nDjango settings must be configured to:\n - load `SECRET_KEY` and `STATIC_ROOT` from the environment:\n    ```python\n    SECRET_KEY=environ.get('SECRET_KEY')\n    STATIC_ROOT=environ.get('STATIC_ROOT')\n    ```\n - load `ALLOWED_HOSTS` from a comma separated list environment variable:\n    ```python\n    ALLOWED_HOSTS = list(environ.get('ALLOWED_HOSTS', default='').split(','))\n    ```\n - use exactly this `DATABASES` configuration:\n    ```python\n    DATABASES = {\n        'default': {\n            'ENGINE': 'django.db.backends.postgresql',\n            'NAME': environ.get('DB_NAME'),\n            'HOST': '',\n        }\n    }\n    ```\n\nTo serve static files out of the box, include the whitenoise middleware:\n```python\nMIDDLEWARE += [ 'whitenoise.middleware.WhiteNoiseMiddleware' ]\nSTATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'\n```\n\n(See `./examples/djangoproject/djangoproject/settings_nix.py` for full example)\n\n\n## Secrets / Keys\nTo pass secrets to django securely:\n1. Create a file containing your secrets as environment variables like this:\n    ```\n    export SECRET_KEY=\"foo\"\n    export ANOTHER_SECRET_FOR_DJANGO=\"bar\"\n    ```\n2. Pass the path of the file via parameter `keys-file`  \n    This file will not be managed by nix.\n    If you are deploying to a remote host, make sure this file is available. An example on how to do this with NixOps can be found under `./examples/nixops`\n\nA systemd service running as root will later pick up that file and copy it to a destination under `/run/` where only the django system user can read it. Make sure by yourself to protect the source file you uploaded to the remote host with proper permissions or use the provided NixOps example.\n\n## Examples\nSee `Readme.md` inside `./examples`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavHau%2Fdjango-nixos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDavHau%2Fdjango-nixos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavHau%2Fdjango-nixos/lists"}