forked from e-valuation/EvaP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
140 lines (130 loc) · 5.21 KB
/
flake.nix
File metadata and controls
140 lines (130 loc) · 5.21 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{
description = "EvaP";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:adisbladis/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
services-flake.url = "github:juspay/services-flake";
};
outputs = { self, nixpkgs, ... }@inputs:
let
lib = nixpkgs.lib;
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
forAllSystems = lib.genAttrs systems;
pkgsFor = lib.genAttrs systems (system: import nixpkgs { inherit system; });
in
{
devShells = forAllSystems (system:
let
pkgs = pkgsFor.${system};
dependency-groups = if pkgs.stdenv.isDarwin then [ "psycopg-c" ] else [ "psycopg-binary" ];
in
rec {
evap = pkgs.callPackage ./nix/shell.nix {
inherit (self.packages.${system}) python3;
inherit (inputs) pyproject-nix uv2nix pyproject-build-systems;
inherit dependency-groups;
our-packages = self.packages.${system};
workspaceRoot = ./.;
};
evap-dev = evap.override (prev: { dependency-groups = (prev.dependency-groups or [ ]) ++ [ "dev" ]; });
evap-dev-with-lsp = evap-dev.override (prev: {
dependency-groups = (prev.dependency-groups or [ ]) ++ [ "lsp" ];
extraPackages = (prev.extraPackages or [ ]) ++ [ pkgs.typescript-language-server ];
});
evap-frontend-dev = evap-dev.overrideAttrs (prev: { nativeBuildInputs = (prev.nativeBuildInputs or [ ]) ++ (with pkgs; [ firefox geckodriver ]); });
default = evap-dev;
impure = pkgs.mkShell {
packages = with pkgs; [
(self.packages.${system}.python3)
uv
postgresql.pg_config
];
env = {
UV_NO_SYNC = "1";
UV_PYTHON = self.packages.${system}.python3.interpreter;
UV_PYTHON_DOWNLOADS = "never";
};
shellHook = ''
unset PYTHONPATH
'';
};
});
packages = forAllSystems (system:
let
pkgs = pkgsFor.${system};
pc-modules = import ./nix/services.nix {
inherit pkgs;
inherit (self.devShells.${system}.evap.passthru) venv;
};
make-process-compose = with-devenv-setup: (import inputs.process-compose-flake.lib { inherit pkgs; }).makeProcessCompose {
modules = [
inputs.services-flake.processComposeModules.default
pc-modules.databases
(lib.mkIf with-devenv-setup pc-modules.devenv-setup)
];
};
in
rec {
python3 = pkgs.python311;
services = make-process-compose false;
services-full = make-process-compose true;
wait-for-pc = pkgs.writeShellApplication {
name = "wait-for-pc";
runtimeInputs = [ pkgs.jq ];
text = ''
echo "Waiting for process-compose to become ready..."
while [ "$(${lib.getExe services} process list -o json 2>/dev/null | jq '.[] |= .is_ready == "Ready" or .status == "Completed" or .status == "Disabled" | all')" != "true" ]; do
sleep 1
done
echo "... done waiting."
'';
};
build-dist = pkgs.writeShellApplication {
name = "build-dist";
runtimeInputs = with pkgs; [ nodejs gettext git ];
text =
let
python-dev = self.devShells.${system}.evap-dev.passthru.venv;
python-build = self.packages.${system}.python3.withPackages (ps: [ ps.build ]);
in
''
set -x
npm ci
${python-dev}/bin/python ./manage.py compilemessages
${python-dev}/bin/python ./manage.py scss --production
${python-dev}/bin/python ./manage.py ts compile --fresh
${python-build}/bin/python -m build
'';
};
check_dist =
let
py = self.packages.${system}.python3.withPackages (ps: [ ps.pathspec ]);
in
pkgs.writeShellScriptBin "check_dist" "${py}/bin/python ${./tools/check_dist.py} $@";
clean-setup = pkgs.writeShellApplication {
name = "clean-setup";
runtimeInputs = with pkgs; [ git ];
text = ''
read -r -p "Delete node_modules/, data/, generated CSS and JS files in evap/static/, and evap/localsettings.py? [y/N] "
[[ "$REPLY" =~ ^[Yy]$ ]] || exit 1
git clean -f -X evap/static/ node_modules/ data/ evap/localsettings.py
'';
};
});
};
}