-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
76 lines (72 loc) · 2.14 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{
description = "Create Nix development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, pyproject-nix }:
let
pyproject = import (pyproject-nix + "/lib") { inherit (nixpkgs) lib; };
# Load/parse requirements.txt
project = pyproject.project.loadRequirementsTxt {
requirements = ./requirements.txt;
};
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
# Create a custom Python environment with pip
pythonWithPackages = python.withPackages (ps: with ps; [
pip
virtualenv
]);
in
{
devShell = pkgs.mkShell {
buildInputs = [
pkgs.postgresql
];
packages = [
pythonWithPackages
# PostgreSQL dependencies
pkgs.postgresql
pkgs.pkg-config
pkgs.pnpm
# Pillow dependencies
pkgs.docker-compose
pkgs.libjpeg
pkgs.zlib
pkgs.libtiff
pkgs.freetype
pkgs.lcms2
pkgs.libwebp
pkgs.tcl
pkgs.tk
pkgs.harfbuzz
pkgs.fribidi
pkgs.libraqm
# OpenSSL
pkgs.openssl
pkgs.pyright
];
shellHook = ''
# Create and activate a virtual environment if it doesn't exist
if [ ! -d .venv ]; then
${pythonWithPackages}/bin/python -m venv .venv
fi
source .venv/bin/activate
# Set up environment variables for Pillow
export LDFLAGS="$LDFLAGS -L${pkgs.libjpeg.out}/lib"
export CPPFLAGS="$CPPFLAGS -I${pkgs.libjpeg.dev}/include"
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
'';
};
});
}