forked from Nix-Security-WG/nix-security-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
114 lines (103 loc) · 3.13 KB
/
default.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
{
sources ? import ./npins,
overlay ? import ./nix/overlay.nix,
pkgs ? import sources.nixpkgs { overlays = [ overlay ]; },
}:
let
self = rec {
inherit pkgs;
inherit (pkgs) python3;
localPythonPackages = import ./pkgs { inherit pkgs python3; };
# For exports.
overlays = [ overlay ];
package = pkgs.web-security-tracker;
module = import ./nix/web-security-tracker.nix;
pre-commit-check = pkgs.pre-commit-hooks {
src = ./.;
hooks =
let
pythonExcludes = [
"/migrations/" # auto-generated code
];
in
{
# Nix setup
nixfmt-rfc-style.enable = true;
statix = {
enable = true;
settings.ignore = [ "staging" ];
};
deadnix.enable = true;
# Python setup
ruff = {
enable = true;
excludes = pythonExcludes;
};
ruff-format = {
enable = true;
name = "Format python code with ruff";
types = [
"text"
"python"
];
entry = "${pkgs.lib.getExe pkgs.ruff} format";
excludes = pythonExcludes;
};
pyright =
let
pyEnv = pkgs.python3.withPackages (_: pkgs.web-security-tracker.propagatedBuildInputs);
wrappedPyright = pkgs.runCommand "pyright" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
makeWrapper ${pkgs.pyright}/bin/pyright $out \
--set PYTHONPATH ${pyEnv}/${pyEnv.sitePackages} \
--prefix PATH : ${pyEnv}/bin \
--set PYTHONHOME ${pyEnv}
'';
in
{
enable = true;
entry = pkgs.lib.mkForce (builtins.toString wrappedPyright);
excludes = pythonExcludes;
};
# Global setup
prettier = {
enable = true;
excludes = [
"\\.min.css$"
"\\.html$"
] ++ pythonExcludes;
};
commitizen.enable = true;
};
};
shell =
let
manage = pkgs.writeScriptBin "manage" ''
${python3}/bin/python ${toString ./src/website/manage.py} $@
'';
in
pkgs.mkShell {
REDIS_SOCKET_URL = "unix:///run/redis/redis.sock";
# `./src/website/tracker/settings.py` by default looks for LOCAL_NIXPKGS_CHECKOUT
# in the root of the repo. Make it the default here for local development.
LOCAL_NIXPKGS_CHECKOUT = toString ./. + "/nixpkgs";
packages = [
manage
package
pkgs.nix-eval-jobs
pkgs.npins
pkgs.hivemind
] ++ pre-commit-check.enabledPackages;
shellHook = ''
${pre-commit-check.shellHook}
mkdir -p .credentials
export DATABASE_URL=postgres:///nix-security-tracker
export CREDENTIALS_DIRECTORY=${builtins.toString ./.credentials}
'';
};
tests = import ./nix/tests/vm-basic.nix {
inherit pkgs;
wstModule = module;
};
};
in
self // self.tests