-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
183 lines (177 loc) · 6.13 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{
description = "example flake";
nixConfig = {
bash-prompt = ''\n\[\033[1;32m\][nix-develop:\w]\$\[\033[0m\] '';
extra-trusted-public-keys = [
"fastapi-mvc.cachix.org-1:knQ8Qo41bnhBmOB6Sp0UH10EV76AXW5o69SbAS668Fg="
];
extra-substituters = [
"https://fastapi-mvc.cachix.org"
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
flake-parts.url = "github:hercules-ci/flake-parts";
poetry2nix = {
url = "github:nix-community/poetry2nix?ref=1.42.0";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-parts, poetry2nix }@inputs:
let
mkApp =
{ drv
, name ? drv.pname or drv.name
, exePath ? drv.passthru.exePath or "/bin/${name}"
}:
{
type = "app";
program = "${drv}${exePath}";
};
in
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
# Add poetry2nix overrides to nixpkgs
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.poetry2nix ];
};
packages =
let
mkProject =
{ python ? pkgs.python3
}:
pkgs.callPackage ./default.nix {
inherit python;
poetry2nix = pkgs.poetry2nix;
};
in
{
default = mkProject { };
example-py38 = mkProject { python = pkgs.python38; };
example-py39 = mkProject { python = pkgs.python39; };
example-py310 = mkProject { python = pkgs.python310; };
example-py311 = mkProject { python = pkgs.python311; };
example-dev = pkgs.callPackage ./editable.nix {
poetry2nix = pkgs.poetry2nix;
python = pkgs.python3;
};
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
image = pkgs.callPackage ./image.nix {
inherit pkgs;
app = config.packages.default;
};
};
overlayAttrs = {
inherit (config.packages) default;
};
apps = {
example = mkApp { drv = config.packages; };
metrics = {
type = "app";
program = toString (pkgs.writeScript "metrics" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
]}"
echo "[nix][metrics] Run example PEP 8 checks."
flake8 --select=E,W,I --max-line-length 88 --import-order-style pep8 --statistics --count example
echo "[nix][metrics] Run example PEP 257 checks."
flake8 --select=D --ignore D301 --statistics --count example
echo "[nix][metrics] Run example pyflakes checks."
flake8 --select=F --statistics --count example
echo "[nix][metrics] Run example code complexity checks."
flake8 --select=C901 --statistics --count example
echo "[nix][metrics] Run example open TODO checks."
flake8 --select=T --statistics --count example tests
echo "[nix][metrics] Run example black checks."
black --check example
'');
};
docs = {
type = "app";
program = toString (pkgs.writeScript "docs" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
]}"
echo "[nix][docs] Build example documentation."
sphinx-build docs site
'');
};
unit-test = {
type = "app";
program = toString (pkgs.writeScript "unit-test" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
]}"
echo "[nix][unit-test] Run example unit tests."
pytest tests/unit
'');
};
integration-test = {
type = "app";
program = toString (pkgs.writeScript "integration-test" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
pkgs.coreutils
]}"
echo "[nix][integration-test] Run example unit tests."
pytest tests/integration
'');
};
coverage = {
type = "app";
program = toString (pkgs.writeScript "coverage" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
pkgs.coreutils
]}"
echo "[nix][coverage] Run example tests coverage."
pytest --cov=example --cov-fail-under=90 --cov-report=xml --cov-report=term-missing tests
'');
};
mypy = {
type = "app";
program = toString (pkgs.writeScript "mypy" ''
export PATH="${pkgs.lib.makeBinPath [
config.packages.example-dev
pkgs.git
]}"
echo "[nix][mypy] Run example mypy checks."
mypy example
'');
};
test = {
type = "app";
program = toString (pkgs.writeScript "test" ''
${config.apps.unit-test.program}
${config.apps.integration-test.program}
'');
};
};
devShells = {
default = config.packages.example-dev.env.overrideAttrs (oldAttrs: {
buildInputs = [
pkgs.git
pkgs.poetry
];
});
poetry = import ./shell.nix { inherit pkgs; };
};
};
flake = {
overlays.poetry2nix = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(import ./overlay.nix)
];
};
};
}