All this information is also included in the README.md
Initialize using
nix flake init --template "github:nulladmin1/nix-flake-templates#python-poetry"
OR Initialize using
nix flake init --template "github:nulladmin1/nix-flake-templates#poetry"
This is how the structure of the template looks like:
📦 python-poetry
├── ⚙️ .envrc
├── 🙈 .gitignore
├── 📃 README.md
├── ❄️ flake.nix
├── 📁 project_name
│ ├── 🐍 __init__.py
│ └── 🐍 main.py
└── ⚙️ pyproject.toml
It includes a basic Poetry project that returns an SHA256 encoded string of the user's input.
The flake is able to run in the specified systems listed in the flake. It contains a devShells
as an output with Python
and Poetry
, and an app as an output that builds a Poetry
project using poetry2nix
. This section is inspired by the official docs for poetry2nix
Run app
nix run
Drop into a development shell
nix develop
Install project and its dependencies
poetry install
Run app
poetry run app
Drop into a development shell
nix develop
Install project and its dependencies
poetry install
Run Pytest
poetry run pytest
(Optional) Format flake.nix
using Alejandra
nix fmt
-
In
flake.nix
- Edit description
{ description = "project_name"; }
- Update the location of the binary
{ program = "${app}/bin/project_name"; }
- Edit description
-
-
Change name, version, description, and authors of the project
[tool.poetry] name = "project_name" version = "0.1.0" description = "" authors = ["Your Name <[email protected]>"]
-
Remove and add needed dependencies using
poetry add ...
[tool.poetry.dependencies] python = "^3.12" [tool.poetry.group.dev.dependencies] pytest = "^8.3.3"
-
Change the name of the scripts and path
[tool.poetry.scripts] project_name = "project_name.main:main"
-
-
For the structure and code
- Rename the
app/
directory to the name of your project. Make sure its the same as the path in thepyproject.toml
📦 python-poetry ├─ 📁 project_name │ ├─ 🐍 __init__.py │ └─ 🐍 main.py
- Add necessary code for the program in the previous subdirectory.
- Make sure that for the
__init__.py
, that it imports from the name of your project, and it imports the necessary functions to be used as a libraryfrom project_name.main import main, get_sha256
- Rename the
-
Execution
- If running the project using
Poetry
, run using:where PROJECT_NAME is the name of the project. Make sure it matches the name of the script in thepoetry run PROJECT_NAME
pyproject.toml
where ${PROJECT_NAME} is the name of the project, and the ${PROJECT_DIR} is the location of the project (recommended to be the same as the PROJECT_NAME). By default it's:[tool.poetry.scripts] PROJECT_NAME = "PROJECT_DIR.main:main"
app/
- If running the project using