How to Run a Django Flake with Poetry2Nix

I’m trying to build and run a Django web application using Poetry2Nix and flakes. Here is my directory structure:

The parent directory is nix_django:

├── flake.lock
├── flake.nix
├── nix_django
│   └──
├── poetry.lock
├── pyproject.toml
├── tango_with_django_project
│   ├── db.sqlite3
│   ├──
│   └── tango_with_django_project
│       ├──
│       ├──
│       ├──
│       ├──
│       └──
└── tests

I’m able to start the app by executing these commands:

nix develop
cd tango_with_django_project
python runserver

I’m also able to build it by executing nix build. So far so good.

The issue is that I don’t know how to create a “nix compliant” binary. I think ideally I would like to run something like result/bin/my-app and have it give me the same results as the command above.

The poetry2nix app recommends doing this by adding something like the following to my pyproject.toml file:

rs = "runserver:run_my_server"

However, when I try to run result/bin/rs I get the following error:

Traceback (most recent call last):
  File "/nix/store/314q4y5cmkrimhi4s5rwylv8zc3q2whz-python3.10-nix-django-0.1.0/bin/.rs-wrapped", line 6, in <module>
    from runserver import run_my_server
ModuleNotFoundError: No module named 'runserver'

Here is my flake.nix file:

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

  outputs = { self, nixpkgs }:
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
      packages = forAllSystems (system: {
        default = pkgs.${system}.poetry2nix.mkPoetryApplication { projectDir = self; };

      devShells = forAllSystems (system: {
        default = pkgs.${system}.mkShellNoCC {
          packages = with pkgs.${system}; [
            (poetry2nix.mkPoetryEnv {
              projectDir = self;

Also, here is my script:

import subprocess

def run_my_server():
    cmd = ['python', 'tango_with_django_project/', 'runserver']

Does anyone know which step I’m missing?

Did you ever get this figured out?

Maybe it’s just me not knowing how poetry works, but isn’t supposed to be inside a project directory like tango_with_django_project? I thought poetry only uses this subdirectory-based approach. Or maybe you can write something like

rs = "../runserver:run_my_server"
1 Like